如何在scrapy中抓取给定的网址而不是重定向的网址?

时间:2015-10-20 07:07:43

标签: python scrapy

我想从亚马逊的this page抓取,但是scrapy总是将我引导到another page,其图像小于第一页。因此,我想停止重定向和抓取第一页。

经过一番搜索后,我找到了this answer。但是当我改变我的代码时:

yield Request(item['link'],meta = {
                  'dont_redirect': True,
                  'handle_httpstatus_list': [301,302]
              }, callback=self.parse)

它会停止重定向,但它也不解析第一页!我的日志是这样的:

2015-10-20 14:56:40 [scrapy] INFO: Scrapy 1.0.3 started (bot: amazon)
2015-10-20 14:56:40 [scrapy] INFO: Optional features available: ssl, http11
2015-10-20 14:56:40 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'amazon.spiders', 'SPIDER_MODULES': ['amazon.spiders'], 'BOT_NAME': 'amazon'}
2015-10-20 14:56:40 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2015-10-20 14:56:40 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, HttpProxyMiddleware, ChunkedTransferMiddleware, DownloaderStats
2015-10-20 14:56:40 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2015-10-20 14:56:40 [scrapy] INFO: Enabled item pipelines: AmazonPipeline
2015-10-20 14:56:40 [scrapy] INFO: Spider opened
2015-10-20 14:56:40 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2015-10-20 14:56:40 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2015-10-20 14:56:41 [scrapy] DEBUG: Crawled (301) <GET http://www.amazon.com/s/ref=sr_il_ti_computers?rh=n%3A172282%2Cn%3A!493964%2Cn%3A541966%2Cn%3A565108%2Cp_n_size_browse-bin%3A7817231011&ie=UTF8&qid=1445324149&lo=computers> (referer: None)
2015-10-20 14:56:41 [scrapy] INFO: Closing spider (finished)
2015-10-20 14:56:41 [scrapy] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 361,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 423,
 'downloader/response_count': 1,
 'downloader/response_status_count/301': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2015, 10, 20, 6, 56, 41, 743646),
 'log_count/DEBUG': 2,
 'log_count/INFO': 7,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2015, 10, 20, 6, 56, 40, 868227)}

有人对此有任何想法吗? THX!

1 个答案:

答案 0 :(得分:0)

你用callback = self.parse调用什么函数?