2017-08-11 53 views
1

在終端,我跑有沒有辦法在shell中處理scrapy.Request對象?

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我得到

現在

,我跑

>>> 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'> 

我想獲得一個新的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' 

回答

1

使用fetch()

>>> fetch(response.follow(next_page)) 
相關問題