def login_qzone_qq_com(self): # 登录qzone.qq.com # 访问网页,为了获取参数pt_login_sig login_url = 'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https://qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=手机QQ空间&pt_qr_link=https://z.qzone.com/download.html&self_regurl=https://qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=https://z.qzone.com/download.html&pt_no_auth=0' html = get_html(login_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = dict_from_cookiejar(html.cookies) pt_login_sig = cookies_back_dict['pt_login_sig'] self.cookies_merge_dict_in_qzone_qq_com.update(cookies_back_dict) # 访问网页,为了获取参数ptqrtoken qrcode_url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=4&d=72&v=4&t=0.0010498811219192827&daid=5&pt_3rd_aid=0' html = get_html(qrcode_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = dict_from_cookiejar(html.cookies) qrsig = cookies_back_dict['qrsig'] ptqrtoken = hash33_token(qrsig) self.cookies_merge_dict_in_qzone_qq_com.update(cookies_back_dict) # 将二维码显示到图片框 BytesIOObj = BytesIO() BytesIOObj.write(html.content) qr_code = PIL.Image.open(BytesIOObj) image = PIL.ImageTk.PhotoImage(qr_code) image_label['image'] = image # 实时检测二维码状态 while (True): # 目标网址 target_url = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https://qzs.qq.com/qzone/v5/loginsucc.html?para=izone&ptqrtoken=' + str( ptqrtoken ) + '&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-1558286321351&js_ver=19042519&js_type=1&login_sig=' + str( pt_login_sig) + '&pt_uistyle=40&aid=549000912&daid=5&' # 登录,需要带上访问cookies html = get_html(target_url, self.cookies_merge_dict_in_qzone_qq_com) # 返回的响应码为200说明二维码没过期 if (html.status_code): if ('二维码未失效' in html.text): custom_print(u'(3/3)登录qzone.qq.com中,当前二维码未失效,请你扫描二维码进行登录') elif ('二维码认证' in html.text): custom_print(u'(3/3)登录qzone.qq.com中,扫描成功,正在认证中') elif ('登录成功' in html.text): self.is_login = True custom_print(u'(3/3)登录qzone.qq.com中,登录成功') break if ('二维码已经失效' in html.text): custom_print(u'(3/3)登录qzone.qq.com中,当前二维码已失效,请重启本软件') exit() # 延时 time.sleep(2) # 登录成功后,把返回的cookies合并进去 cookies_back_dict = dict_from_cookiejar(html.cookies) self.cookies_merge_dict_in_qzone_qq_com.update(cookies_back_dict) # 获取此次登录的qq号码 qq_list = re.findall(r'&uin=(.+?)&service', html.text) self.qq_number = qq_list[0] # 登录成功后,会返回一个地址,需要对该地址进行访问以便获取新的返回cookies startIndex = (html.text).find('http') endIndex = (html.text).find('pt_3rd_aid=0') url = (html.text)[startIndex:endIndex] + 'pt_3rd_aid=0' # 屏蔽https证书警告 urllib3.disable_warnings() # 这里需要注意的是,需要禁止重定向,才能正确获得返回的cookies html = get(url, cookies=self.cookies_merge_dict_in_qzone_qq_com, allow_redirects=False, verify=False) # 把返回的cookies合并进去 cookies_back_dict = dict_from_cookiejar(html.cookies) self.cookies_merge_dict_in_qzone_qq_com.update(cookies_back_dict)
def login_id_qq_com(self): # 登录id.qq.com # 访问网页,为了获取参数pt_login_sig login_url = 'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?pt_disable_pwd=1&appid=1006102&daid=1&style=23&hide_border=1&proxy_url=https://id.qq.com/login/proxy.html&s_url=https://id.qq.com/index.html' html = get_html(login_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = requests.utils.dict_from_cookiejar(html.cookies) pt_login_sig = cookies_back_dict['pt_login_sig'] self.cookies_merge_dict_in_id_qq_com.update(cookies_back_dict) # 访问网页,为了获取参数ptqrtoken qrcode_url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=1006102&e=2&l=M&s=3&d=72&v=4&t=0.10239549811477189&daid=1&pt_3rd_aid=0' html = get_html(qrcode_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = requests.utils.dict_from_cookiejar(html.cookies) qrsig = cookies_back_dict['qrsig'] ptqrtoken = hash33_token(qrsig) self.cookies_merge_dict_in_id_qq_com.update(cookies_back_dict) # 将登录二维码写到本地,并自动打开,让用户扫描 with open('qrcode2.png', "wb") as f: f.write(html.content) # 调用系统默认打开方式,打开该二维码 open_file_by_system('qrcode2.png') # 实时检测二维码状态 while (True): # 目标网址 target_url = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https://id.qq.com/index.html&ptqrtoken=' + str( ptqrtoken ) + '&ptredirect=1&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-1556812236254&js_ver=19042519&js_type=1&login_sig=' + str( pt_login_sig) + '&pt_uistyle=40&aid=1006102&daid=1&' # 登录,需要带上访问cookies html = get_html(target_url, self.cookies_merge_dict_in_id_qq_com) # 返回的响应码为200说明二维码没过期 if (html.status_code): if ('二维码未失效' in html.text): print(u'登录id.qq.com中,当前二维码未失效,请你扫描二维码进行登录') elif ('二维码认证' in html.text): print(u'登录id.qq.com中,扫描成功,正在认证中') elif ('登录成功' in html.text): self.is_login = True print(u'登录id.qq.com中,登录成功') break if ('二维码已经失效' in html.text): print(u'登录id.qq.com中,当前二维码已失效,请重启本软件') exit() # 延时 time.sleep(2) # 登录成功后,把返回的cookies合并进去 self.cookies_merge_dict_in_id_qq_com = requests.utils.dict_from_cookiejar( html.cookies) self.cookies_merge_dict_in_id_qq_com.update(cookies_back_dict) # print(u'当前cookies:{}'.format(cookies_merge_dict)) # 获取此次登录的qq号码 qq_list = re.findall(r'&uin=(.+?)&service', html.text) self.qq_number = qq_list[0] # 登录成功后,会返回一个地址,需要对该地址进行访问以便获取新的返回cookies startIndex = (html.text).find('http') endIndex = (html.text).find('pt_3rd_aid=0') url = (html.text)[startIndex:endIndex] + 'pt_3rd_aid=0' # 屏蔽https证书警告 requests.packages.urllib3.disable_warnings() # 这里需要注意的是,需要禁止重定向,才能正确获得返回的cookies html = requests.get(url, cookies=self.cookies_merge_dict_in_id_qq_com, allow_redirects=False, verify=False) # 把返回的cookies合并进去 cookies_back_dict = requests.utils.dict_from_cookiejar(html.cookies) self.cookies_merge_dict_in_id_qq_com.update(cookies_back_dict)
def __init__(self): self.is_login = False self.cookies_merge_dict = '' self.qq_number = '' # 访问网页,为了获取参数pt_login_sig login_url = 'http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&s_url=http://qun.qq.com/member.html' html = get_html(login_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict1 = requests.utils.dict_from_cookiejar(html.cookies) pt_login_sig = cookies_back_dict1['pt_login_sig'] # 访问网页,为了获取参数ptqrtoken qrcode_url = 'https://ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=4&t=0.39550762134604156' html = get_html(qrcode_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict2 = requests.utils.dict_from_cookiejar(html.cookies) qrsig = cookies_back_dict2['qrsig'] ptqrtoken = hash33_token(qrsig) # 将登录二维码写到本地,并自动打开,让用户扫描 with open('qrcode.png', "wb") as f: f.write(html.content) # 调用系统默认打开方式,打开该二维码 open_file_by_system('qrcode.png') # 对返回的两个cookies进行合并,作为提交cookies cookies_merge_dict = {} cookies_merge_dict.update(cookies_back_dict1) cookies_merge_dict.update(cookies_back_dict2) print(u'当前cookies:{}'.format(cookies_merge_dict)) # 实时检测二维码状态 while (True): # 目标网址 target_url = 'http://ptlogin2.qq.com/ptqrlogin?u1=http%3A%2F%2Fqun.qq.com%2Fmember.html&' + 'ptqrtoken=' + str( ptqrtoken ) + '&ptredirect=1&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-1499652067577&js_ver=10224&js_type=1&login_sig=' + str( pt_login_sig) + '&pt_uistyle=40&aid=549000912&' # 登录,需要带上访问cookies html = get_html(target_url, cookies_merge_dict) # 返回的响应码为200说明二维码没过期 if (html.status_code): if ('二维码未失效' in html.text): print(u'当前二维码未失效,请你扫描二维码进行登录') elif ('二维码认证' in html.text): print(u'扫描成功,正在认证中') elif ('登录成功' in html.text): self.is_login = True print(u'登录成功') break if ('二维码已经失效' in html.text): print(u'当前二维码已失效,请重启本软件') exit() # 延时 time.sleep(2) # 登录成功后,把返回的cookies合并进去 cookies_back_dict = requests.utils.dict_from_cookiejar(html.cookies) cookies_merge_dict.update(cookies_back_dict) # print(u'当前cookies:{}'.format(cookies_merge_dict)) # 获取此次登录的qq号码 qq_list = re.findall(r'&uin=(.+?)&service', html.text) self.qq_number = qq_list[0] # 登录成功后,会返回一个地址,需要对该地址进行访问以便获取新的返回cookies startIndex = (html.text).find('http') endIndex = (html.text).find('pt_3rd_aid=0') url = (html.text)[startIndex:endIndex] + 'pt_3rd_aid=0' # 这里需要注意的是,需要禁止重定向,才能正确获得返回的cookies html = requests.get(url, cookies=cookies_merge_dict, allow_redirects=False) # 把返回的cookies合并进去 cookies_back_dict = requests.utils.dict_from_cookiejar(html.cookies) cookies_merge_dict.update(cookies_back_dict) # print(u'当前cookies:{}'.format(cookies_merge_dict)) self.cookies_merge_dict = cookies_merge_dict
def login_qun_qq_com(self): # 登录qun.qq.com # 访问网页,为了获取参数pt_login_sig login_url = 'http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&s_url=http://qun.qq.com/member.html' html = get_html(login_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = dict_from_cookiejar(html.cookies) pt_login_sig = cookies_back_dict['pt_login_sig'] self.cookies_merge_dict_in_qun_qq_com.update(cookies_back_dict) # 访问网页,为了获取参数ptqrtoken qrcode_url = 'https://ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=4&d=72&v=4&t=0.39550762134604156' html = get_html(qrcode_url, '') # 对返回的cookies进行转化为dict类型,方便处理 cookies_back_dict = dict_from_cookiejar(html.cookies) qrsig = cookies_back_dict['qrsig'] ptqrtoken = hash33_token(qrsig) self.cookies_merge_dict_in_qun_qq_com.update(cookies_back_dict) # 将二维码显示到图片框 BytesIOObj = BytesIO() BytesIOObj.write(html.content) qr_code = PIL.Image.open(BytesIOObj) image = PIL.ImageTk.PhotoImage(qr_code) image_label['image'] = image # 实时检测二维码状态 while (True): # 目标网址 target_url = 'http://ptlogin2.qq.com/ptqrlogin?u1=http://qun.qq.com/member.html&' + 'ptqrtoken=' + str( ptqrtoken ) + '&ptredirect=1&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-1499652067577&js_ver=10224&js_type=1&login_sig=' + str( pt_login_sig) + '&pt_uistyle=40&aid=549000912&' # 登录,需要带上访问cookies html = get_html(target_url, self.cookies_merge_dict_in_qun_qq_com) # 返回的响应码为200说明二维码没过期 if (html.status_code): if ('二维码未失效' in html.text): custom_print(u'(2/2)登录qun.qq.com中,当前二维码未失效,请你扫描二维码进行登录') elif ('二维码认证' in html.text): custom_print(u'(2/2)登录qun.qq.com中,扫描成功,正在认证中') elif ('登录成功' in html.text): self.is_login = True custom_print(u'(2/2)登录qun.qq.com中,登录成功') break if ('二维码已经失效' in html.text): custom_print(u'(2/2)登录qun.qq.com中,当前二维码已失效,请重启本软件') exit() # 延时 time.sleep(2) # 登录成功后,把返回的cookies合并进去 cookies_back_dict = dict_from_cookiejar(html.cookies) self.cookies_merge_dict_in_qun_qq_com.update(cookies_back_dict) # print(u'当前cookies:{}'.format(cookies_merge_dict)) # 获取此次登录的qq号码 qq_list = re.findall(r'&uin=(.+?)&service', html.text) self.qq_number = qq_list[0] # 登录成功后,会返回一个地址,需要对该地址进行访问以便获取新的返回cookies startIndex = (html.text).find('http') endIndex = (html.text).find('pt_3rd_aid=0') url = (html.text)[startIndex:endIndex] + 'pt_3rd_aid=0' # 这里需要注意的是,需要禁止重定向,才能正确获得返回的cookies html = get(url, cookies=self.cookies_merge_dict_in_qun_qq_com, allow_redirects=False) # 把返回的cookies合并进去 cookies_back_dict = dict_from_cookiejar(html.cookies) self.cookies_merge_dict_in_qun_qq_com.update(cookies_back_dict)