zoukankan      html  css  js  c++  java
  • Python 实现腾讯微博模拟登录 (附源码)

    实现登录基本功能,代码略乱,欢迎来喷 大家可以交流下,再改进(分析过程不一一赘述了,直接看源码吧)

    import hashlib
    import string
    import binascii
    import random,re
    import urllib,urllib2
    from datetime import datetime
    import cookielib
    
    #get verifycode
    def GetVC(uin,appid):
    
        r = random.random()
    
        url = "https://ssl.ptlogin2.qq.com/check?regmaster=&uin="+uin+"&appid="+appid+"&login_sig=ZhpNArA4ZZE*CE0MaxDd6Ct0iLVRfbM0oeUg3Jb6lMg0KlD-bvZL3uhjxsZMtiFm&js_ver=10070&js_type=1&u1=http%3A%2F%2Ft.qq.com&r="+str(r)
    
        req = urllib2.Request(url)
        res = urllib2.urlopen(req)
        
      #获取cookie中ptvfsession 里面应该加密了verifycode,否则提示验证码错误 fsession
    = re.findall(r'ptvfsession=.*?;',res.headers['Set-Cookie'])[0][12:-1] vc = res.read()[18:22] return vc,fsession #first md5 def Md5_3(psd): m1 = hashlib.md5() m1.update(psd) arr = [] for i in range(0,len(m1.hexdigest().upper()),2): arr.append(binascii.unhexlify(m1.hexdigest().upper()[i:i+2])) cc= ''.join(arr) return cc #the last two md5 def Md5_Final(psd,vc): uin = "x00x00x00x00x5axc9xacx1e" #GetVC处获得 m2 = hashlib.md5() m2.update(Md5_3(psd)+uin) m3 = hashlib.md5() m3.update(m2.hexdigest().upper()+vc.upper()) return m3.hexdigest().upper() #cookie set #login def WeiboLogin(psd,vc,fsession,uin,appid): p = Md5_Final(psd,vc) login_url = "https://ssl.ptlogin2.qq.com/login?u="+uin+"&verifycode="+vc+"&p="+p+"&pt_rsa=0&ptredirect=1&u1=http%3A%2F%2Ft.qq.com&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=3-11-1394781854509&js_ver=10071&js_type=1&login_sig=-D2cTMFy15OnGwJzhgDyshuLSUj4eO3VnTeDE9ThK1xKz4R-EWA-srijzKREoXXk&aid=46000101&daid=6" headers = {"User-Agent":"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36"} req = urllib2.Request(login_url,headers = headers) coo = "RK=zHnnAz5VX+; ptcz=26fb7729591c82b442a343d1ef0e1ab15cc9aa0dae24c538d8db9e764f9452ae; pt2gguin=o1523166238; pgv_info=ssid=s8312227920; pgv_pvid=3545103816; o_cookie=1523166238; confirmuin=0; ptvfsession="+fsession+"; ptisp=; qrsig=6Fv1OFRrjZGuA87NR2Ht7pAWulbq59YR3L0k3dowIX7n*KOHs1OsIf-yuYfB-GHU; ptui_loginuin=1523166238" req.add_header("Accept","*/*") req.add_header("Accept-Encoding","gzip,deflate,sdch") req.add_header("Accept-Language","zh-CN,zh;q=0.8") req.add_header("Connection","keep-alive") req.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6") req.add_header("Host","ssl.ptlogin2.qq.com") req.add_header("Referer","https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=46000101&style=23&lang=&low_login=1&hide_border=1&hide_title_bar=1&hide_close_icon=1&border_radius=1&self_regurl=http%3A//reg.t.qq.com/index.php&proxy_url=http://t.qq.com/proxy_t.html&s_url=http%3A%2F%2Ft.qq.com&daid=6") req.add_header("Cookie",coo) res = urllib2.urlopen(req) print res.read() if __name__ == "__main__": psd = "密码" uin = "帐号" appid = "46000101" vc,fsession = GetVC(uin,appid) WeiboLogin(psd,vc,fsession,uin,appid)

    登录成功返回信息

    ptuiCB('0','0','跳转连接','1','登录成功!', '微博昵称');
  • 相关阅读:
    IEEE Bigger系列题解
    Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学
    Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs
    Codeforces Round #354 (Div. 2) C. Vasya and String 二分
    Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟
    Codeforces Round #354 (Div. 2) A. Nicholas and Permutation 水题
    Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列
    Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
    2016 UESTC DP专题题解
    HDU 5701 中位数计数 暴力
  • 原文地址:https://www.cnblogs.com/jeesezhang/p/3600786.html
Copyright © 2011-2022 走看看