问题
When I use PHP to get cookie, it returns:
session_id=abih14s7l4lgo3splta7f6bd14; cccaa78fa9e13785130119a4924db0f4=96637ae... (more)
But when I use Python, it returns:
session_id=abih14s7l4lgo3splta7f6bd14
... the rest of cookies is lost.
My code Python:
res_post = requests.post(LOGIN_URL, data = {mydata})
cookies = dict(res_post.cookies.items())
回答1:
Looks like you're using the requests library. The response.cookies is already a dictionary, so there's no need to cast it again.
You should access the cookies on the response like so:
response = requests.post(LOGIN_URL, data={mydata})
print response.cookies['session_id']
See here for more detail: http://docs.python-requests.org/en/latest/user/quickstart/#cookies
来源:https://stackoverflow.com/questions/34113005/get-set-cookie-in-header-using-requests-module