import requests
url = 'https://passport.csdn.net/account/login'
sess = requests.session()
t = sess.get(url).text
re = 'name="lt" value="'
start = t.index(re)
lt = t[start+len(re):start+len(re)+41]
re = 'name="execution" value="'
start = t.index(re)
execution = t[start+len(re):start+len(re)+4]
if '"' in lt:
lt = lt[:lt.index('"')]
data = {
"lt": lt,
"execution": execution,
"_eventId": "submit",
"username": "xxxxxx",
"password": "xxxxxx"
}
r = sess.post(url, data)
print sess.get('http://msg.csdn.net/').text
url = 'https://passport.csdn.net/account/login'
sess = requests.session()
t = sess.get(url).text
re = 'name="lt" value="'
start = t.index(re)
lt = t[start+len(re):start+len(re)+41]
re = 'name="execution" value="'
start = t.index(re)
execution = t[start+len(re):start+len(re)+4]
if '"' in lt:
lt = lt[:lt.index('"')]
data = {
"lt": lt,
"execution": execution,
"_eventId": "submit",
"username": "xxxxxx",
"password": "xxxxxx"
}
r = sess.post(url, data)
print sess.get('http://msg.csdn.net/').text