为scrapy shell 请求设置标头 [英] Set headers for scrapy shell request

查看:53
本文介绍了为scrapy shell 请求设置标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know that you can scrapy shell -s USER_AGENT='custom user agent' 'http://www.example.com' to change the USER_AGENT, but how do you add request headers?

推荐答案

目前没有直接在 cli 上添加标题的方法,但您可以执行以下操作:

there is no current way to add headers directly on cli, but you could do something like:

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

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

This will update the current shell information with that new request.

这篇关于为scrapy shell 请求设置标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆