设置
我正在尝试用Scrapy抓取this page。
在草率的shell中,我使用USER_AGENT在网页上获得了正确的200
,即
scrapy shell -s USER_AGENT='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' 'https://www.seloger.com/list.htm?abslc=new&enterprise=0&natures=1,2,4&places=[{cp:77}]&projects=2,5&qsversion=1.0&types=1,2&bd=DetailToList_SL&abSLC=new'
问题
在我的实际脚本中,使用相同的USER_AGENT,Scrapy得到了404,
2018-12-17 11:54:48 [scrapy.utils.log] INFO: Scrapy 1.3.3 started (bot: france)
2018-12-17 11:54:48 [scrapy.utils.log] INFO: Overridden settings: {'BOT_NAME': 'france', 'FEED_FORMAT': 'csv', 'FEED_URI': 'test.csv', 'NEWSPIDER_MODULE': 'france.spiders', 'SPIDER_MODULES': ['france.spiders'], 'USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'}
2018-12-17 11:54:48 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.feedexport.FeedExporter',
'scrapy.extensions.logstats.LogStats']
2018-12-17 11:54:48 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2018-12-17 11:54:48 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
'scrapy.spidermiddlewares.referer.RefererMiddleware',
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
'scrapy.spidermiddlewares.depth.DepthMiddleware']
2018-12-17 11:54:48 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-12-17 11:54:48 [scrapy.core.engine] INFO: Spider opened
2018-12-17 11:54:48 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-12-17 11:54:48 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6026
2018-12-17 11:54:49 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.seloger.com/list.htm?abslc=new&enterprise=0&natures=1,2,4&places=%5B%7Bcp:77%7D%5D&projects=2,5&qsversion=1.0&types=1,2&bd=DetailToList_SL&abSLC=new> (referer: None)
2018-12-17 11:54:49 [scrapy.dupefilters] DEBUG: Filtered duplicate request: <GET https://www.seloger.com/h> - no more duplicates will be shown (see DUPEFILTER_DEBUG to show all duplicates)
2018-12-17 11:54:49 [scrapy.core.engine] DEBUG: Crawled (404) <GET https://www.seloger.com/h> (referer: https://www.seloger.com/list.htm?abslc=new&enterprise=0&natures=1,2,4&places=%5B%7Bcp:77%7D%5D&projects=2,5&qsversion=1.0&types=1,2&bd=DetailToList_SL&abSLC=new)
2018-12-17 11:54:49 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 https://www.seloger.com/h>: HTTP status code is not handled or not allowed
2018-12-17 11:54:50 [scrapy.core.engine] INFO: Closing spider (finished)
2018-12-17 11:54:50 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 1126,
'downloader/request_count': 2,
'downloader/request_method_count/GET': 2,
'downloader/response_bytes': 75148,
'downloader/response_count': 2,
'downloader/response_status_count/200': 1,
'downloader/response_status_count/404': 1,
'dupefilter/filtered': 19,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2018, 12, 17, 10, 54, 50, 1680),
'log_count/DEBUG': 4,
'log_count/INFO': 8,
'request_depth_max': 1,
'response_received_count': 2,
'scheduler/dequeued': 2,
'scheduler/dequeued/memory': 2,
'scheduler/enqueued': 2,
'scheduler/enqueued/memory': 2,
'start_time': datetime.datetime(2018, 12, 17, 10, 54, 48, 476223)}
2018-12-17 11:54:50 [scrapy.core.engine] INFO: Spider closed (finished)
我已经在ROBOTSTXT_OBEY = False
中尝试过settings.py
。
我可以解决这个问题吗?如果可以,怎么办?