前几天研究了下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())
发表评论