我在使用python登陆知乎如何输入确定验证码,代码是我在社区中搜到的,我实验了一下,求解释一下错误
import requests
import re
import time
from subprocess import Popen
headers ={
'Accept':'*/*' ,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With':'XMLHttpRequest',
'Referer':'http://www.zhihu.com',
'Accept-Language':'zh-CN',
'Accept-Encoding':'gzip, deflate',
'User-Agent':'Mozilla/5.0(Windows NT 6.1;WOW64;Trident/7.0;rv:11.0)like Gecko',
'Host':'www.zhihu.com'
}
s =requests.session()
r = s.get('http://www.zhihu.com',headers =headers)
def getXSRF(r):
cer = re.compile('name=\"_xsrf\" value=\"(.*)\"', flags = 0)
strlist = cer.findall(r.text)
return strlist[0]
_xsrf =getXSRF(r)
print(r.request.headers)
print(str(int(time.time()*1000)))
Captcha_URL= 'http://www.zhihu.com/captcha.gif?r='+ str(int(time.time()*1000))
r = s.get(Captcha_URL,headers =headers)
with open('code.gif','wb') as f:
f.write(r.content)
Popen('code.gif',shell =True)
captcha =input('captcha: ')
login_data = {
'_xsrf':_xsrf,
'email':'xxxxx@xxxx.com',
'password': 'xxxxxxxx,
'remember_me':'true',
'captcha':captcha
}
r = s.post('http://www.zhihu.com/login/email',data=login_data,headers=headers)
print(r.text)
r = s.get('http://www.zhihu.com/settings/profile')
print(r.text)
{'Accept-Language': 'zh-CN', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'Mozilla/5.0(Windows NT 6.1;WOW64;Trident/7.0;rv:11.0)like Gecko', 'Host': 'www.zhihu.com', 'Referer': 'http://www.zhihu.com', 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
1445417491333
captcha: "fjkm"
{
"r": 1,
"errcode": 1991829,
"data": {"captcha":"\u8bf7\u63d0\u4ea4\u6b63\u786e\u7684\u9a8c\u8bc1\u7801 :("},
"msg": "\u8bf7\u63d0\u4ea4\u6b63\u786e\u7684\u9a8c\u8bc1\u7801 :("
}
<!doctype html>
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ç¥ä¹</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://static.zhihu.com/static/css/desktop/errors.css" />
<link rel="shortcut icon" href="http://static.zhihu.com/static/img/favicon.ico" />
</head>
<body>
<div class="page">
<div class="error error-wide">
<div class="header">
<a href="/" id="page_logo" class="fl">
<img src="http://static.zhihu.com/static/img/logo_black_trans.png" alt="ç¥ä¹">
</a>
<strong class="mute">ä¸ä¸ªçå®çé®ç社åº</strong>
</div>
<div class="content">
<p class="single">æå¡å¨æäºä¸ä¸ªé®é¢ï¼æ们æ£å¨ç´§å¼ å°æ°åçæ¡...</p>
</div>
</div>
</div>
<script src="http://static.zhihu.com/static/js/desktop/500.js"></script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的机器人原来就是这样挂掉的.以前知乎是不用输验证码的.