0

I am new to scrapy and trying to submit a form and scrape the response from https://www.fbo.gov/index?s=opportunity&tab=search&mode=list.

When I use the scrapy shell:

scrapy shell "https://www.fbo.gov/index?s=opportunity&tab=search&mode=list"

it opens up the shell but contains no response object. Running

print(response)

returns none. I've tried using just "https://www.fbo.gov" and other variations but nothing seems to work. The example I followed used "http://quotes.toscrape.com/page/1/" and it works fine.

Why do I get no response when using a different URL? Does it have to do with the https? Do I need to use a FormRequest to get an response since the link contains a form? I figured it would at least return the html of the form. I plan to 'check' various checkboxes upon submit.

Thanks in advance for any help!

Log:

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
4

1 回答 1

0

你的日志说:

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

当您“打开一个新终端”时它起作用的原因是您可能从非项目目录启动了 shell,而 scrapy 不再从您的项目中获取此设置。

于 2017-08-10T04:57:52.370 回答