鱼C论坛

 找回密码
 立即注册
查看: 4817|回复: 1

python百度登录,老是提示error=6,验证码错误

[复制链接]
发表于 2017-2-5 11:59:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import requests as rs
import time
import re
import datetime
import random
import urllib.parse as p
class login:
    def __init__(self,username,password):
        self.username=username
        self.password=password
        self.se=rs.session()
        self.data={}
        self.data['ppui_logintime']=random.randint(10000,9999999)
        self.data['charset']='utf-8'
        self.data['codestring']=self.get_codestring()
        self.data['token']=self.get_token()
        self.data['isPhone']='false'
        self.data['index']='0'
        self.data['u']=''
        self.data['safeflg']='0'
        self.data['staticpage']='http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fjump.html'
        self.data['loginType']='1'
        self.data['tpl']='mn'
        self.data['callback']='parent.bdPass.api.login._postCallback'
        self.data['username']=self.username
        self.data['password']=self.password
        self.data['verifycode']=self.get_verify()
        self.data['mem_pass']='on'
        self.head = {}
        self.head['User-Agent'] = 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) appleWebKit/537.36 (KHTML, like Gecko' \
                            ') Chrome/55.0.2883.87 Mobile Safari/537.36'
        print(self.data)
    def get_codestring(self):
        url='https://passport.baidu.com/v2/api/?logincheck&callback=bdPass.api.login._needCodestringCheckCallback&tpl=' \
            'mn&charset=UTF-8&index=0&username='+self.username+'&isphone=false&time='+self.get_posttime()
        html = self.se.get(url).text
        match = re.compile("codestring\":\"(.*?)\"")
        codestring = match.findall(html)[0]
        return codestring
    def get_token(self):
        rs.get('http://news.baidu.com/')
        url='https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true'
        html=self.se.get(url).text
        match = re.compile("token='(.*?)'")
        token = match.findall(html)[0]
        return token
    def get_verify(self):
        url='https://passport.baidu.com/cgi-bin/genimage?'+self.data['codestring']+'&v='+self.get_posttime()
        html=self.se.get(url).content
        with open(r'C:\Users\Mr-zhang\Desktop\pic.png','wb') as f:
            f.write(html)
        verify=input('请输入验证码')
        verify={'verify':verify}
        verify=p.urlencode(verify)[7:]
        return verify
    def get_posttime(self):
        now_time = str(int(time.mktime(datetime.datetime.now().timetuple())))
        return now_time
    def main(self):
        post_url='https://passport.baidu.com/v2/api/?login'
        response=self.se.post(post_url,data=self.data,headers=self.head).text
        print(response)
if __name__ == '__main__':
    s=login('******','******')
    s.main()

上面是python代码,提示 https:\/\/passport.baidu.com\/v2Jump.html?callback=parent.bdPass.api.login._postCallback&index=0&codestring=tcG1107e245a01dc1ba02e914ce9801ac7b34a444061f043196&username=+‘用户名’+&phonenumber=&mail=&tpl=mn&u=https%3A%2F%2Fpassport.baidu.com%2F&needToModifyPassword=&gotourl=&auth=&error=6');
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-2-5 12:00:09 | 显示全部楼层
验证码是我读取到本地,然后输入进去的,不知道怎么回事,总是提示不对,求大牛帮忙看看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 12:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表