精易论坛

标题: 百度登录,老是提示error=6,验证码错误 [打印本页]

作者: 孟婆来碗汤啊    时间: 2017-2-5 11:50
标题: 百度登录,老是提示error=6,验证码错误
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');

作者: 孟婆来碗汤啊    时间: 2017-2-5 11:51
验证码是我读取到本地,然后输入进去的,不知道怎么回事,总是提示不对,求大牛帮忙看看
作者: 中华威少    时间: 2017-2-5 11:55
小学进来学习的
作者: 2725925825    时间: 2017-2-5 13:02
楼主发错版块了 应该去 易求助
作者: longtengxp    时间: 2017-2-6 17:31
打印下登录提交的数据,对比下你抓包的,看下有什么错误!
作者: 序列号    时间: 2017-2-7 17:22
应该是验证码改变了吧
作者: 南方的雪    时间: 2018-5-15 11:11
把headers字段填完整,看浏览器上怎么写的。copy一份。





欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4