为什么我的基本 scrapy 请求没有得到响应?
Why does my basic scrapy request get no response?
我是 scrapy 的新手,正在尝试提交表单并抓取 https://www.fbo.gov/index?s=opportunity&tab=search&mode=list 的回复。
当我使用scrapy时shell:
scrapy shell "https://www.fbo.gov/index?s=opportunity&tab=search&mode=list"
它打开 shell 但不包含响应对象。 运行
print(response)
returns none。
我试过只使用“https://www.fbo.gov" and other variations but nothing seems to work. The example I followed used "http://quotes.toscrape.com/page/1/”,效果很好。
为什么我使用不同的 URL 时没有任何反应?跟https有关系吗?我是否需要使用 FormRequest 来获得响应,因为 link 包含一个表单?我认为它至少会 return 表格的 html。我计划在提交时 'check' 各种复选框。
在此先感谢您的帮助!
日志:
2017-08-09 21:45:43 [scrapy.utils.log] INFO: Scrapy 1.4.0 started (bot: fbg)
2017-08-09 21:45:43 [scrapy.utils.log] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'fbg.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['fbg.spiders'], 'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter', 'BOT_NAME': 'fbg', 'LOGSTATS_INTERVAL': 0}
2017-08-09 21:45:44 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole']
2017-08-09 21:45:44 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
'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.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2017-08-09 21:45:45 [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']
2017-08-09 21:45:45 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2017-08-09 21:45:45 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2017-08-09 21:45:45 [scrapy.core.engine] INFO: Spider opened
2017-08-09 21:45:45 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.fbo.gov/robots.txt> (referer: None)
2017-08-09 21:45:45 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
[s] Available Scrapy objects:
[s] scrapy scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s] crawler <scrapy.crawler.Crawler object at 0x1101058d0>
[s] item {}
[s] request <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
[s] settings <scrapy.settings.Settings object at 0x1101059e8>
[s] Useful shortcuts:
[s] fetch(url[, redirect=True]) Fetch URL and update local objects (by default, redirects are followed)
[s] fetch(req) Fetch a scrapy.Request and update local objects
[s] shelp() Shell help (print this help)
[s] view(response) View response in a browser
您的日志显示:
2017-08-09 21:45:45 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
您似乎已将 ROBOTSTXT_ENABLED
设置为 True
,因此您的请求被过滤掉了。尝试在您的项目中禁用它或 运行 scrapy shell url -s ROBOTSTXT_ENABLED=0
它在您 "opened a new terminal" 时起作用的原因是您可能 shell 从非项目目录启动并且 scrapy 不再从您的项目中获取此设置。
我是 scrapy 的新手,正在尝试提交表单并抓取 https://www.fbo.gov/index?s=opportunity&tab=search&mode=list 的回复。
当我使用scrapy时shell:
scrapy shell "https://www.fbo.gov/index?s=opportunity&tab=search&mode=list"
它打开 shell 但不包含响应对象。 运行
print(response)
returns none。 我试过只使用“https://www.fbo.gov" and other variations but nothing seems to work. The example I followed used "http://quotes.toscrape.com/page/1/”,效果很好。
为什么我使用不同的 URL 时没有任何反应?跟https有关系吗?我是否需要使用 FormRequest 来获得响应,因为 link 包含一个表单?我认为它至少会 return 表格的 html。我计划在提交时 'check' 各种复选框。
在此先感谢您的帮助!
日志:
2017-08-09 21:45:43 [scrapy.utils.log] INFO: Scrapy 1.4.0 started (bot: fbg)
2017-08-09 21:45:43 [scrapy.utils.log] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'fbg.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['fbg.spiders'], 'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter', 'BOT_NAME': 'fbg', 'LOGSTATS_INTERVAL': 0}
2017-08-09 21:45:44 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole']
2017-08-09 21:45:44 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
'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.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
2017-08-09 21:45:45 [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']
2017-08-09 21:45:45 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2017-08-09 21:45:45 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2017-08-09 21:45:45 [scrapy.core.engine] INFO: Spider opened
2017-08-09 21:45:45 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.fbo.gov/robots.txt> (referer: None)
2017-08-09 21:45:45 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
[s] Available Scrapy objects:
[s] scrapy scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s] crawler <scrapy.crawler.Crawler object at 0x1101058d0>
[s] item {}
[s] request <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
[s] settings <scrapy.settings.Settings object at 0x1101059e8>
[s] Useful shortcuts:
[s] fetch(url[, redirect=True]) Fetch URL and update local objects (by default, redirects are followed)
[s] fetch(req) Fetch a scrapy.Request and update local objects
[s] shelp() Shell help (print this help)
[s] view(response) View response in a browser
您的日志显示:
2017-08-09 21:45:45 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.fbo.gov/index?s=opportunity&tab=search&mode=list>
您似乎已将 ROBOTSTXT_ENABLED
设置为 True
,因此您的请求被过滤掉了。尝试在您的项目中禁用它或 运行 scrapy shell url -s ROBOTSTXT_ENABLED=0
它在您 "opened a new terminal" 时起作用的原因是您可能 shell 从非项目目录启动并且 scrapy 不再从您的项目中获取此设置。