设置scrapy shell请求的标头

oct*_*ron 15 scrapy scrapy-shell

我知道您可以scrapy shell -s USER_AGENT='custom user agent' 'http://www.example.com'更改USER_AGENT,但是如何添加请求标头?

eLR*_*uLL 36

目前没有直接在cli上添加标题的方法,但你可以这样做:

$ scrapy shell
...
...
>>> from scrapy import Request
>>> req = Request('yoururl.com', headers={"header1":"value1"})
>>> fetch(req)
Run Code Online (Sandbox Code Playgroud)

这将使用该新请求更新当前shell信息.