当前位置:网站首页 > 更多 > 编程开发 > 正文

[Python] 用python代码扫码登陆QQ空间获取Cookie值,QQ登陆协议,python模拟登陆QQ

作者:CC下载站 日期:2020-06-02 00:00:00 浏览:71 分类:编程开发

前几天研究了下QQ群的几个接口,但是最后面都需要手动输入Cookie才可以运行,然后今天又研究了一下QQ空间的登陆接口,然后就有了下面这些代码,最终的返回值是登录成功的Cookie值。需要手动打开目录下的qrcode.png然后进行扫码。

import re
import time
from random import random

import requests


def hash33(t):
    e = 0
 for i in range(len(t)):
        e += (e << 5) + ord(t[i])
    return 2147483647 & e


def login():
    ss = requests.session()
    url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=' + str(
        '0.' + str(int(random() * 10000000000000000)))
    response = ss.get(url=url)
    with open('qrcode.png', 'wb') as f:
        f.write(response.content)
    cookie = response.cookies
    headers = requests.utils.dict_from_cookiejar(cookie)
    print(headers)
    while True:
        url = f'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fqzs.qzone.qq.com%2Fqzone%2Fv5%2Floginsucc.html' 
              f'%3Fpara%3Dizone%26from%3Diqq&ptqr' 
              f'token={hash33(headers["qrsig"])}&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0' 
              f'-1542784335061&js_ver=10289&js_type=1&login_sig=hn6ZiMZRPT8LWFsFG3MrScznzLVrdbwS9EIo-ihAmeD' 
              f'*YmOfqP3uoI6JytVVQYw2&pt_uistyle=40&aid=549000912&daid=5& '
 html = ss.get(url=url, headers=headers)
        type = re.findall('[u4e00-u9fa5]+', html.text)[0]
        if type == '二维码未失效':
            print(type)
        elif type == '二维码认证中':
            print(type)
        elif type == '登录成功':
            print(type)
            return html.cookies
        else:
            print("二维码已失效,请重新扫码!")
            login()
        time.sleep(2)


if __name__ == '__main__':
    print(login())

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯