2017-08-11 14 views
1

は、私は、端末でscrap.Requestオブジェクトをシェルで処理する方法はありますか?ターミナルで

import scrapy 

class QuotesSpider(scrapy.Spider): 
    name = "quotes" 
    start_urls = ['http://quotes.toscrape.com/page/1/'] 

spidersフォルダに以下のクモを作成し、私はこのすべてが同様に正常に動作

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

を走った

scrapy startproject tutorial 

を走りました私が開くPythonシェル

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

は今、私はnext_pageへのリンクに基づいて、シェルで新しいResponseオブジェクトを取得したいと思い

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

を走りました。これはまったく可能ですか?どのような助けも非常に感謝します。

私は下記を試しましたが、エラーを修正できませんでした。

>>> 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)) 
関連する問題