Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate spider variable when using shell.inspect_response #2812

Merged
merged 1 commit into from Jul 24, 2017

Conversation

elacuesta
Copy link
Member

Currently the spider variable is not populated when using scrapy.inspect_response. It can be accessed through crawler.spider, but I think this could still be useful.

Before:

2017-07-03 11:07:18 [scrapy.core.engine] INFO: Spider opened
2017-07-03 11:07:18 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
[s] Available Scrapy objects:
[s]   scrapy     scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s]   crawler    <scrapy.crawler.Crawler object at 0x7f5c17d50c50>
[s]   item       {}
[s]   request    <GET http://www.example.org>
[s]   response   <200 http://www.example.org>
[s]   settings   <scrapy.settings.Settings object at 0x7f5c17d508d0>
[s] Useful shortcuts:
[s]   shelp()           Shell help (print this help)
[s]   view(response)    View response in a browser
>>> type(spider)
<type 'NoneType'>

After:

2017-07-03 11:26:10 [scrapy.core.engine] INFO: Spider opened
2017-07-03 11:26:10 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
[s] Available Scrapy objects:
[s]   scrapy     scrapy module (contains scrapy.Request, scrapy.Selector, etc)
[s]   crawler    <scrapy.crawler.Crawler object at 0x7f5237c2ddd8>
[s]   item       {}
[s]   request    <GET http://www.example.org>
[s]   response   <200 http://www.example.org>
[s]   settings   <scrapy.settings.Settings object at 0x7f5237c2dda0>
[s]   spider     <TestSpider 'inspect' at 0x7f523497add8>
[s] Useful shortcuts:
[s]   shelp()           Shell help (print this help)
[s]   view(response)    View response in a browser
>>> type(spider)
<class 'inspect_spider.TestSpider'>

@redapple
Copy link
Contributor

redapple commented Jul 3, 2017

Makes sense! +1

@codecov-io
Copy link

Codecov Report

Merging #2812 into master will increase coverage by 0.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master    #2812      +/-   ##
==========================================
+ Coverage    84.7%   84.71%   +0.01%     
==========================================
  Files         163      163              
  Lines        9177     9177              
  Branches     1363     1363              
==========================================
+ Hits         7773     7774       +1     
  Misses       1150     1150              
+ Partials      254      253       -1
Impacted Files Coverage Δ
scrapy/shell.py 68.61% <0%> (ø) ⬆️
scrapy/utils/trackref.py 86.48% <0%> (+2.7%) ⬆️

@dangra
Copy link
Member

dangra commented Jul 24, 2017

No pushbacks, I guess acceding spider from shell inspection is so common that the need for a shortcut would be useful.

@kmike kmike merged commit 17bbd71 into scrapy:master Jul 24, 2017
@kmike
Copy link
Member

kmike commented Jul 24, 2017

Thanks!

@elacuesta elacuesta deleted the inspect_response_populate_spider branch March 15, 2018 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants