2014-11-21 98 views
2

我開始抓取CrawlSpider Derived類,並用Ctrl + C暫停它。當我再次執行命令以恢復它時,它不會繼續。Scrapy抓取簡歷不抓取任何東西,只是完成

我的啓動和恢復命令:

scrapy crawl mycrawler -s JOBDIR=crawls/test5_mycrawl 

Scrapy創建該文件夾。權限是777

當我恢復抓取,它只是輸出:

/home/adminuser/.virtualenvs/rg_harvest/lib/python2.7/site-packages/twisted/internet/_sslverify.py:184: UserWarning: You do not have the service_identity module installed. Please install it from <https://pypi.python.org/pypi/service_identity>. Without the service_identity module and a recent enough pyOpenSSL tosupport it, Twisted can perform only rudimentary TLS client hostnameverification. Many valid certificate/hostname mappings may be rejected. 
    verifyHostname, VerificationError = _selectVerifyImplementation() 
2014-11-21 11:05:10-0500 [scrapy] INFO: Scrapy 0.24.4 started (bot: rg_harvest_scrapy) 
2014-11-21 11:05:10-0500 [scrapy] INFO: Optional features available: ssl, http11, django 
2014-11-21 11:05:10-0500 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'rg_harvest_scrapy.spiders', 'SPIDER_MODULES': ['rg_harvest_scrapy.spiders'], 'BOT_NAME': 'rg_harvest_scrapy'} 
2014-11-21 11:05:10-0500 [scrapy] INFO: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState 
2014-11-21 11:05:10-0500 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats 
2014-11-21 11:05:10-0500 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware 
2014-11-21 11:05:10-0500 [scrapy] INFO: Enabled item pipelines: ValidateMandatory, TypeConversion, ValidateRange, ValidateLogic, RestegourmetImagesPipeline, SaveToDB 
2014-11-21 11:05:10-0500 [mycrawler] INFO: Spider opened 
2014-11-21 11:05:10-0500 [mycrawler] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 
2014-11-21 11:05:10-0500 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023 
2014-11-21 11:05:10-0500 [scrapy] DEBUG: Web service listening on 127.0.0.1:6080 
2014-11-21 11:05:10-0500 [mycrawler] DEBUG: Crawled (200) <GET http://eatsmarter.de/suche/rezepte> (referer: None) 
2014-11-21 11:05:10-0500 [mycrawler] DEBUG: Filtered duplicate request: <GET http://eatsmarter.de/suche/rezepte?page=1> - no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates) 
2014-11-21 11:05:10-0500 [mycrawler] INFO: Closing spider (finished) 
2014-11-21 11:05:10-0500 [mycrawler] INFO: Dumping Scrapy stats: 
    {'downloader/request_bytes': 225, 
    'downloader/request_count': 1, 
    'downloader/request_method_count/GET': 1, 
    'downloader/response_bytes': 19242, 
    'downloader/response_count': 1, 
    'downloader/response_status_count/200': 1, 
    'dupefilter/filtered': 29, 
    'finish_reason': 'finished', 
    'finish_time': datetime.datetime(2014, 11, 21, 16, 5, 10, 733196), 
    'log_count/DEBUG': 4, 
    'log_count/INFO': 7, 
    'request_depth_max': 1, 
    'response_received_count': 1, 
    'scheduler/dequeued': 1, 
    'scheduler/dequeued/disk': 1, 
    'scheduler/enqueued': 1, 
    'scheduler/enqueued/disk': 1, 
    'start_time': datetime.datetime(2014, 11, 21, 16, 5, 10, 528629)} 

我有一個START_URL。這可能是原因嗎?我的抓取工具使用一個START_URL,然後遵循與LinkExtractor規則分頁,並通過特定的URL格式調用解析項目:

我的蜘蛛代碼:

class MyCrawlSpiderBase(CrawlSpider): 
    name = 'test_spider' 

    testmode = True 
    crawl_start = datetime.utcnow().isoformat() 

    def __init__(self, testmode=True, urls=None, *args, **kwargs):   
     self.testmode = bool(int(testmode)) 
     super(MyCrawlSpiderBase, self).__init__(*args, **kwargs)   

    def parse_item(self, response): 
     # Item Values 
     l = MyItemLoader(RecipeItem(), response=response) 

     l.replace_value('url', response.url) 
     l.replace_value('crawl_start', self.crawl_start) 

     return l.load_item() 


class MyCrawlSpider(MyCrawlSpiderBase): 
    name = 'example_de' 
    allowed_domains = ['example.de'] 
    start_urls = [ 
     "http://example.de", 

    ] 

    rules = (
     Rule( 
      LinkExtractor( 
       allow=('/search/entry\?page=',) 
      ) 
     ), 


     Rule(
      LinkExtractor(
       allow=('/entry/[0-9A-z\-]{3,}$',), 
      ), 
      callback='parse_item' 
     ), 
    ) 

    def parse_item(self, response): 
     item = super(MyCrawlSpider, self).parse_item(response) 

     l = MyItemLoader(item=item, response=response) 

     l.replace_xpath("name", "//h1[@class='fn title']/text()")   

     (...) 

     return l.load_item() 
+0

請張貼您的蜘蛛代碼。你使用cookies嗎?或請求序列化? – 2014-11-21 19:59:51

+0

我添加了蜘蛛代碼。我不使用cookies,我不確定我是否使用請求序列化... – user1383029 2014-11-22 16:17:14

回答

1

如果您單擊Ctrl + C兩次(強制停止),它將無法繼續。單擊Ctrl + C一次並等待。

5

由於您的網址始終是相同的,這些請求很可能被過濾。 您可以通過兩種方式解決這個問題:

  1. 在你settings.py文件,加入這一行:
    DUPEFILTER_CLASS = 'scrapy.dupefilter.BaseDupeFilter'
    這將替換默認RFPDupeFilterBaseDupeFilter,不會過濾任何請求。如果你實際上想過濾出與這個問題無關的其他請求,我不會成爲你想要的。

  2. 您可以更多地參與創建請求的過程,並使用參數dont_filter=True創建它們,該參數將禁用基於每個請求的過濾。爲了達到這個目的,你可以刪除start_urls並用一個方法start_requests()代替它,這會產生解析請求。查看official documentation中的更多信息。