更改 python 请求中的引用 URL [英] Changing the referer URL in python requests

查看:22
本文介绍了更改 python 请求中的引用 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用请求库向网页发出 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 dict 将与默认/会话标头合并.来自文档:

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 请求中的引用 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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