request模拟你登录待验证码的网站,返回的总是验证码错误,求解决

EricSun888 2018-12-14 04:28:12
url = 'https://www.123.com/user/login/login.html'
capturl = 'https://www.123.com/user/login/selfverify.html'
cookie = cookiejar.MozillaCookieJar()
handler = request.HTTPCookieProcessor(cookie)
opener = request.build_opener(handler)
username = 'name888'
password = '123'
picture = opener.open(capturl).read()
with open('验证码.jpg','wb') as f:
f.write(picture)
PIL.Image.open('验证码.jpg').show()
valicode = input("请输入验证:")
postData = {'username':username,'password':password,'code':valicode}
header = {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","Accept-Encoding":"gzip, deflate, br","Accept-Language": "zh-CN,zh;q=0.9","Cache-Control":"max-age=0","Connection":"keep-alive","Content-Length":"49","Content-Type":"pplication/x-www-form-urlencoded","Cookie":"PHPSESSID=6epdc1hh7i23gmk1qn6t04bd64","Host":"www.fageka.com","Origin":"https://www.fageka.com", "Referer":"https://www.fageka.com/user/login/login.html","Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"}
postData = parse.urlencode(postData).encode('utf-8')
req = request.Request(url,postData,header)
# res = request.urlopen(req).read().decode('utf-8')
res = opener.open(req).read().decode('utf-8')
print(res)
...全文
248 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧