有办法处理吗恶心。请求外壳中的对象?

2024-05-19 16:10:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在候机楼,我跑了

scrapy startproject tutorial

我在spiders文件夹中创建了以下蜘蛛

^{pr2}$

在候机楼,我跑了

scrapy shell 'http://quotes.toscrape.com/page/1/'

这一切在pythonshell中运行得很好

>>> response
<200 http://quotes.toscrape.com/page/1/>

现在,我跑了

>>> next_page = response.css('li.next a::attr(href)').extract_first()
>>> next_page
'/page/2/'

>>> response.follow(next_page)
<GET http://quotes.toscrape.com/page/2/>

>>> type(response.follow(next_page))
<class 'scrapy.http.request.Request'>

我想在shell中获得一个新的Response对象,它基于到next_page的链接。这可能吗?非常感谢任何帮助。在

我已经试过下面的方法了,但没能修正这个错误。在

>>> scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware.process_request(response.follow(next_page), "quotes")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: process_request() missing 1 required positional argument: 'spider'

Tags: comhttpresponserequestpageshellprocesstutorial