2017-11-24 13 views
0

예정된 시간에 거미를 여러 번 크롤링하고 싶습니다. 다음 크롤링 시간은 첫 번째 크롤링이 완료된 후에 결정됩니다. 당신은 외부 모듈 일정 시도를 줄 수예약 된 시간에 거미를 크롤링

spidersQ = collections.OrderedDict() 

class QuotesSpider(scrapy.Spider): 
    name = "quotes" 
    global spidersQ 
    start_urls = [ 
     "https://www.amazon.com", 
    ] 

    def parse(self, response): 
     root = lxml.html.fromstring(response.body) 
     lxml_result = root.xpath("(//div[contains(@class,'a-section')]/div[contains(@class,'olpOffer')])[1]") 

     price = lxml_result[0].text.strip() 
     # Now schedule this spider to run again after 5 seconds 
     spidersQ[datetime.datetime.now() + datetime.timedelta(seconds=5)] = QuotesSpider 


def main(): 
    process = CrawlerProcess({ 
     'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)' 
    }) 

    process.crawl(QuotesSpider) 
    process.start(stop_after_crawl=False) # the script will block here forever 

    while True: 
     if datetime.datetime.now() > first(spidersQ): 
      schedTime, spider = spidersQ.popitem(last=False) 
      process.crawl(spider) 
      process.start(stop_after_crawl=False) 
     else: 
      time.sleep(1) 
+0

이 되었습니까 여기 선) 그렇게 내 코드는하지만 코드 (첫 번째 crawler.start에서 차단됩니다 재현 할 수있다. Ctrl + C에서'process.start (...)'줄 다음에 계속됩니다. 이미'CrawlerProcess'와'Ctrl + C'에 관한 버그가있었습니다 (https://github.com/scrapy/scrapy/issues/1279). 어쩌면 그것은 어떻게 든 관련이 있고 관련 스킬 코드 섹션으로 디버깅 할 수 있습니까? – Aufziehvogel

답변