python模拟登录CSDN,提交POST没有反应

当网页采用JavaScript动态技术以后,想封锁你的模拟登录就太容易了,甚至可以根据你的鼠标活动的特征准确地判断出是不是真人在操作,所以,想做通用的模拟登录还得选别的技术,比如,用一个浏览器内容来实现模拟登录,用python控制它
■网友
python 模拟登录csdn并获取博客列表等操作看看这个怎么样,目测可以。以下代码Windows7,Python2.7测试通过。#-*-coding:UTF-8-*-#author:zwgimport urllib,urllib2,re,cookielib#建立带有cookie的openercookie = cookielib.CookieJar()cookieProc = urllib2.HTTPCookieProcessor(cookie)opener = urllib2.build_opener(cookieProc)#opener=urllib2.build_opener()#opener.add_handler(cookieProc)#opener.addheaders(headers)h = opener.open(\u0026#39;https://passport.csdn.net\u0026#39;).read().decode("utf8")patten1 = re.compile(r\u0026#39;name="lt" value="https://www.zhihu.com/api/v4/questions/31519602/(.*?)"\u0026#39;)patten2 = re.compile(r\u0026#39;name="execution" value="https://www.zhihu.com/api/v4/questions/31519602/(.*?)"\u0026#39;)b1 = patten1.findall(h)b2 = patten2.findall(h)postData = https://www.zhihu.com/api/v4/questions/31519602/{ /u0026#39;username/u0026#39;: /u0026#39;username/u0026#39;, /u0026#39;password/u0026#39;: /u0026#39;password/u0026#39;, /u0026#39;lt/u0026#39;: b1, /u0026#39;execution/u0026#39;: b2, /u0026#39;_eventId/u0026#39;: /u0026#39;submit/u0026#39;,}postData= urllib.urlencode(postData)opener.addheaders = response = opener.open(/u0026#39;https://passport.csdn.net/u0026#39;, data=postData)text = response.read()# print(text)# exit()response2 = opener.open(/u0026#39;http://my.csdn.net/my/mycsdn/u0026#39;)text2 = response2.read()file1 = file(/u0026#39;csdn.html/u0026#39;, /u0026#39;w/u0026#39;)file1.write(text2)file1.close()
■网友
我也遇到了同样的问题,登录成功后再次请求csdn首页仍是未登录状态,该怎么解决?
■网友
剧透:前面还会有Js的坑等着你,不要骄傲哦


    推荐阅读