Changing the referer URL in python requests

风流意气都作罢 提交于 2019-11-28 23:35:49

问题


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.


回答1:


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)

Or just:

requests.get(url, headers={'referer': my_referer})

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.



来源:https://stackoverflow.com/questions/20837786/changing-the-referer-url-in-python-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!