python requests get cookies

后端 未结 2 1700
醉梦人生
醉梦人生 2020-11-28 07:17
x = requests.post(url, data=data)
print x.cookies

I used the requests library to get some cookies from a website, but I can only get the cookies fr

2条回答
  •  忘掉有多难
    2020-11-28 07:50

    Alternatively, you can use requests.Session and observe cookies before and after a request:

    >>> import requests
    >>> session = requests.Session()
    >>> print(session.cookies.get_dict())
    {}
    >>> response = session.get('http://google.com')
    >>> print(session.cookies.get_dict())
    {'PREF': 'ID=5514c728c9215a9a:FF=0:TM=1406958091:LM=1406958091:S=KfAG0U9jYhrB0XNf', 'NID': '67=TVMYiq2wLMNvJi5SiaONeIQVNqxSc2RAwVrCnuYgTQYAHIZAGESHHPL0xsyM9EMpluLDQgaj3db_V37NjvshV-eoQdA8u43M8UwHMqZdL-S2gjho8j0-Fe1XuH5wYr9v'}
    

提交回复
热议问题