在终端,我跑了
scrapy startproject tutorial
我在spiders
文件夹
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = ['http://quotes.toscrape.com/page/1/']
在终端,我跑了
scrapy shell 'http://quotes.toscrape.com/page/1/'
这一切都正常,因为在打开的Python shell中我得到了
>>> 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'