在python请求中更改引荐来源网址 [英] Changing the referer URL in python requests
问题描述
如果我使用请求库向网页发出GET请求,如何更改引荐来源网址.我浏览了整个手册,但找不到.
How do I change the referer if I'm using the requests library to make a GET request to a web page. I went through the entire manual but couldn't find it.
推荐答案
根据 http://docs.python-requests.org/en/latest/user/advanced/#session-objects ,您应该可以做到:
According to http://docs.python-requests.org/en/latest/user/advanced/#session-objects , you should be able to do:
s = requests.Session()
s.headers.update({'referer': my_referer})
s.get(url)
或者只是:
requests.get(url, headers={'referer': my_referer})
您的headers
字典将与默认/会话标头合并.从文档:
Your headers
dict will be merged with the default/session headers. From the docs:
您传递给请求方法的任何词典都将与 设置的会话级值.方法级参数 覆盖会话参数.
Any dictionaries that you pass to a request method will be merged with the session-level values that are set. The method-level parameters override session parameters.
这篇关于在python请求中更改引荐来源网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!