使用requests 登录xsrf 验证的网站

使用requests 登录xsrf 验证的网站

import sys
import requests

URL = 'http://xxxxxxx/sign-in'

client = requests.session()

# Retrieve the CSRF token first
client.get(URL)  # sets cookie
csrftoken = client.cookies['_xsrf']
print csrftoken

EMAIL = "xxxx"
PASSWORD = "xxxx"

login_data = dict(name=EMAIL, password=PASSWORD, _xsrf=csrftoken, next='/')

#r = client.post(URL, data=login_data, headers=dict(Referer=URL))
r = client.post(URL, data=login_data)

print r.status_code
print r.text
print r.json()
Relative Articles