Username
Username

Reputation: 3663

Scrapy can't open this URL? `response` is None

When I run these commands...

scrapy shell "https://brpurch.ionwave.net/CurrentSourcingEvents.aspx"
view(response)

I get this error...

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/me/ENV/stuff/local/lib/python2.7/site-packages/scrapy/utils/response.py", line 70, in open_in_browser
    body = response.body
AttributeError: 'NoneType' object has no attribute 'body'

How do I parse this page in Scrapy?

My browser is Chromium v67.0.3396.87. My OS is Debian 9.3.

Here's the full output when I run scrapy shell, before view(response).

2018-07-05 18:57:29 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: pbc_rfp)
2018-07-05 18:57:29 [scrapy.utils.log] INFO: Versions: lxml 4.2.3.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.4.0, w3lib 1.19.0, Twisted 18.4.0, Python 2.7.13 (default, Nov 24 2017, 17:33:09) - [GCC 6.3.0 20170516], pyOpenSSL 18.0.0 (OpenSSL 1.1.0h  27 Mar 2018), cryptography 2.2.2, Platform Linux-4.9.0-6-amd64-x86_64-with-debian-9.4
2018-07-05 18:57:29 [scrapy.crawler] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'pbc_rfp.spiders', 'ROBOTSTXT_OBEY': True, 'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter', 'SPIDER_MODULES': ['pbc_rfp.spiders'], 'BOT_NAME': 'pbc_rfp', 'LOGSTATS_INTERVAL': 0, 'COOKIES_ENABLED': False}
2018-07-05 18:57:29 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.corestats.CoreStats']
2018-07-05 18:57:29 [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.httpproxy.HttpProxyMiddleware',
 'scrapy.downloadermiddlewares.stats.DownloaderStats']
2018-07-05 18:57:29 [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-07-05 18:57:29 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-07-05 18:57:29 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6031
2018-07-05 18:57:29 [scrapy.core.engine] INFO: Spider opened
2018-07-05 18:57:29 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://brpurch.ionwave.net/robots.txt> (referer: None)
2018-07-05 18:57:29 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://brpurch.ionwave.net/CurrentSourcingEvents.aspx>
[s] Available Scrapy objects:
[s]   scrapy     scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s]   crawler    <scrapy.crawler.Crawler object at 0x7f57de8dfa10>
[s]   item       {}
[s]   request    <GET https://brpurch.ionwave.net/CurrentSourcingEvents.aspx>
[s]   settings   <scrapy.settings.Settings object at 0x7f57de8dfb90>
[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

Upvotes: 0

Views: 921

Answers (3)

gangabass
gangabass

Reputation: 10666

You have ROBOTSTXT_OBEY=True (default value) in your settings.py file and scrapy shell reads this value and use it.

You can try this command: scrapy shell https://brpurch.ionwave.net/CurrentSourcingEvents.aspx --set="ROBOTSTXT_OBEY=False"

Upvotes: 1

Joesmaker
Joesmaker

Reputation: 111

I can see the message 'Forbidden by robots.txt'.

Maybe just edit ROBOTSTXT_OBEY=False in your setting.

Similar answer can be found on SO: getting Forbidden by robots.txt: scrapy

Upvotes: 1

nosklo
nosklo

Reputation: 223122

I can't reproduce it - I used the same commands you type and it works fine here. I can see the answer in the browser. Do you get more output? Maybe a traceback? Edit the question and put the full output please.

Upvotes: 0

Related Questions