#!/usr/bin/env python
#coding=utf-8
import requests
import sys
login_home_url="https://passport.csdn.net/account/login?ref=toolbar"
#创建一个session实例,session能记录你的登录账号信息(因为http是短链接,无法记录COOKIE)
# 之前的操作都是基于同一个session进行的,保持会话的有效性
web_sessiOns= requests.Session()
#打开登录页面
LoginPage = web_sessions.get(login_home_url)
print("line14")
# 获取响应的内容,以文本格式
print(LoginPage.text)
#获取当前页面上的元素:元素lt\\execution的值
lt_sting = LoginPage.text[LoginPage.text.find(\'name="lt"\'): LoginPage.text.find("/>",LoginPage.text.find(\'name="lt"\'))]
print("lt_sting: ",lt_sting)
print("*"*30)
lt = lt_sting[lt_sting.find("LT"):-2]
print("lt: ",lt)
exe_sting = LoginPage.text[LoginPage.text.find(\'name="execution"\'): LoginPage.text.find("/>",LoginPage.text.find(\'name="execution"\'))]
print("exe_sting: ",exe_sting)
execution =exe_sting[exe_sting.rfind(\'="\')+2:-2]
print("execution: ",execution)
#提交的用户信息、submit的网站
login_url = "https://passport.csdn.net/account/verify"
userData ={"username":"…………@qq.com","password":"qa……","lt":lt,"execution":execution,"_eventId":"submit"}
#火狐浏览器User-Agent设置
headerstr= {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","Accept": "text/html, application/xhtml+xml, */*"}
#提交post请求
login_respOnse= web_sessions.post(login_url,data=userData,headers=headerstr)
print(login_response.text) #该post请求后响应的结果,不满足预期,待解决。。》》》》
# comment_url = "http://blog.csdn.net/fromsuny_smile/article/details/79014217"
# comment_headers= {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0","Accept": "*/*"}
# comment_payload ={"commentid":"","content":u"很好啦","replyId":""}
# comment_respOnse= web_sessions.post(comment_url,data = comment_payload, headers =comment_headers)
# print(comment_response.text)