# -*- coding:utf8 -*- import requests from lxml import etree headers = { # 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', # 'Accept-Encoding':'gzip, deflate', # 'Accept-Language':'zh-CN,zh;q=0.8', # 'Cache-Control':'max-age=0', # 'Connection':'keep-alive', # 'Cookie': 'remember_token=1|d72f9ce127c036c9300bc985da622b2aebb6dc9453ec42f5796ee87d40c3e13c1f2d8d67fb5424b81c17f290fd98817bd1c1603433ae1890cad78f47aa7d87f4; session=.eJw9UMuOgjAU_ZVJ1y6g4obEBabSsLiXMGlpejcmoygUmElQY6nx34dxMcuTnPeTHc5Tc21ZepvuzYoduhNLn-zji6UMjY5I1qM1dQcq86WEAKEdrcvWwG0Erm5Lox829DO4ywNFtiFpOYaFq4CjyAdUNKAsFrwbSvXpSBYJGnIgLjMG660rEhK7jiR21oAHp9c41n0p8g7ErgUOnGQ-kOs9uSwCAXEpwJOqNqC0B16FUhVb9lqx43U6H24_ffP9P4GknlFWa6v2ERqI_6IX-Yx8qSSGFked2HByMBYJGOpI7L19bN9292szve9gMXv9AkvjYFA.DDT6vA.RvG2-oDGY_S6D37PCx8czxkxQXI', # 'Host':'106.15.185.45:3389', # 'Upgrade-Insecure-Requests':'1', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36', } print headers url = 'https://passport.csdn.net/account/login' s=requests.session() r = s.get(url,headers=headers) sel = etree.HTML(r.content) csrf_token = sel.xpath('//input[@name="lt"]/@value')[0] execution = sel.xpath('//input[@name="execution"]/@value')[0] formdata = { 'username':'xxxx', 'password':'xxxx', 'rememberMe' : 'true', 'lt':csrf_token, 'execution':execution, '_eventId':'submit', } r2 = s.post(url = url, data = formdata, headers = headers) r3 = s.get("http://my.csdn.net",headers=headers) print r3.text