吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 16244|回复: 34
收起左侧

[Python 转载] 一键获取QQ好友手机号-学习Python第一个软件

   关闭 [复制链接]
我来试试 发表于 2021-2-6 16:23
本帖最后由 我来试试 于 2021-2-6 17:58 编辑

首先说明,不发接口!不发接口!!不发接口!!!
第一步
获取QQ空间的cookie
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
from time import sleep
import json
import easygui as g  # 安装easygui库
 
msg = "需要关闭网页QQ登录保护,酌情使用!"  # 填报提示信息
title = "获取QQ好友电话"  # 标题
#偷下懒 密码就不做*号了
fieldNames = ["*QQ", "*QQ密码"# 内容和格式
fieldValues = []  # 拿个空列表装信息
fieldValues = g.multenterbox(msg, title, fieldNames)  # 把信息装进去
while True:
    if fieldValues == None:
        exit()
    errmsg = ""
    for i in range(len(fieldNames)):
        option = fieldNames[i].strip()
        if fieldValues[i].strip() == "" and option[0] == "*":
            errmsg += ("【%s】为必填项   " % fieldNames[i])
    if errmsg == "":
        break
    fieldValues = g.multenterbox(errmsg, title, fieldNames, fieldValues)
 
if fieldValues:
    chromedriver = 'chromedriver.exe'
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    driver = webdriver.Chrome(chromedriver,chrome_options=chrome_options)
 
 
    driver.get('https://user.qzone.qq.com/')
    driver.switch_to.frame('login_frame')
    #找到账号密码登陆的地方
    driver.find_element_by_id('switcher_plogin').click()
    driver.find_element_by_id('u').send_keys(fieldValues[0])
    driver.find_element_by_id('p').send_keys(fieldValues[1])
    driver.find_element_by_id('login_button').click()
    #保存本地的cookie
    sleep(1)
    cookies = driver.get_cookies()
    sleep(1)
    if cookies:
        cookie_dic = {}
        for cookie in cookies:
            if 'name' in cookie and 'value' in cookie:
                cookie_dic[cookie['name']] = cookie['value']
            with open('cookie_dict.txt', 'w') as f:
                json.dump(cookie_dic, f)
        # 关闭chromedriver命令窗口
        os.system("taskkill /f /im chromedriver.exe")
        os.system('taskkill /im chrome.exe /F')


效果如图 QQ截图20210206160643.png
因为刚接触python 还有很多不懂  借鉴了不少论坛里大佬的代码

第二步获取QQ空间的一个装好友信息的JS
链接是这个 https://user.qzone.qq.com/proxy/domain/r.qzone.qq.com/cgi-bin/tfriend/friend_ship_manager.cgi?  
里面还缺少了 一个叫 g_tk 的参数 这个是经过一定算法才获取到的,也是搬的大佬的代码

下面直接放源码了
[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
import time
import json
import urllib
import win32api,win32con
import os
from tkinter import *
import requests
import tkinter as tk
 
#设置header 头
header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:61.0) Gecko/20100101 Firefox/61.0",
        "Accepted-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        "referer": "https://user.qzone.qq.com/"
    }
def get_gtk():
    p_skey = cookie['p_skey']
    h = 5381
    for i in p_skey:
        h += (h << 5) + ord(i)
        g_tk = h & 2147483647
    return g_tk
 
def get_uin():
    uin = cookie['ptui_loginuin']
    return uin
 
#找出好友列表
def get_friend():
    url_friend = 'https://user.qzone.qq.com/proxy/domain/r.qzone.qq.com/cgi-bin/tfriend/friend_ship_manager.cgi?'
    g_tk = get_gtk()
    uin= get_uin()
    data = {
        'uin': uin,
        'do' : 1,
        'g_tk': g_tk
    }
    data_encode = urllib.parse.urlencode(data)
    url_friend += data_encode
    res = requests.get(url_friend, headers = header, cookies = cookie)
    friend_json = re.findall('\((.*)\)',res.text,re.S)[0]
    # print(friend_json)
    friend_dict = json.loads(friend_json)
    friend_result_list = []
    #循环将好友的姓名qq号存入字典中
    for friend in friend_dict['data']['items_list']:
        friend_result_list.append([friend['name'],friend['uin']])
    #得到的好友字典是{name: qqNum}格式的
    return friend_result_list
 
 
def get_mobile(uin):
    url_mobile = "接口?qq={}".format(uin)
 
    try:
        mobile_code = requests.get(url_mobile, timeout=5).status_code
        if mobile_code == 200 and requests.get(url_mobile).text != '404':
            mobile = requests.get(url_mobile).text
            if json.loads(mobile)['qq']!= None:
                return json.loads(mobile)['qq']
        else:
            return "未知"
    except:
        return  "获取失败!"
 
 
if __name__ == "__main__":
#怕被滥用  设置了个时间限制 ###失策了  这个时间是电脑时间  很容易绕
    if time.time()>1612605600:
        exit()
    import cookie
    try:
        with open('cookie_dict.txt', 'r') as f:
            cookie = json.load(f)
        if get_friend():
            file = open('通讯录.txt', 'w',encoding='utf-8')
            get_friend_result = get_friend()
            get_friend_result_len = len(get_friend_result)
 
            window = tk.Tk()
            window.title('正在获取')
            window.geometry('630x150')
 
            # 设置下载进度条
            tk.Label(window, text='获取进度:', ).place(x=50, y=60)
            canvas = tk.Canvas(window, width=465, height=22, bg="white")
            canvas.place(x=110, y=60)
            fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
            x = get_friend_result_len  # 未知变量,可更改
            n = 465 / # 465是矩形填充满的次数
 
            for i in range(0,get_friend_result_len):
                mobile = get_mobile(get_friend_result[i][1])
                name = get_friend_result[i][0]
                # print("\r正在获取好友手机号:{}%".format((i)*100/get_friend_result_len), end="", flush=True)
                file.write(name+'-'+mobile)
                file.write('\n\n')
                #进度条
                n = n + 465 / x
                canvas.coords(fill_line, (0, 0, n, 60))
                window.update()
 
            file.close()
            os.remove('cookie_dict.txt')
            win32api.MessageBox(0, "获取成功!", "提示",win32con.MB_OK)
    except:
        win32api.MessageBox(0, "QQ帐号或者QQ密码错误!请确保已经关闭网页QQ登录保护!\n                           若多次失败,请联系作者!", "提示",win32con.MB_OK)
        os.remove('cookie_dict.txt')


最终效果图 QQ图片20210206161744.png QQ截图20210206161949.png
新人小白,代码很粗糙,看官们轻喷


免费评分

参与人数 5吾爱币 +4 热心值 +5 收起 理由
yang10560 + 1 + 1 牛B,测试通过
woaijiepai + 1 + 1 谢谢@Thanks!
风铭羽 + 1 + 1 我很赞同!
1659906740 + 1 我很赞同!
kk1212 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 我来试试 发表于 2021-2-6 18:00
Dumeng 发表于 2021-2-6 17:56
搞了半天 以为能在QQ空间里获得 手机号

哈哈哈  开头不是说了嘛     主要就是学习一下模拟登陆的流程  和一些  进度条类的辅助功能
虚空先森 发表于 2021-2-6 17:41
vipxy 发表于 2021-2-6 17:53
楼主啊 我完全不会 也看不懂  我可不可把号给你 你帮我看一下。谢谢
Dumeng 发表于 2021-2-6 17:56
搞了半天 以为能在QQ空间里获得 手机号
 楼主| 我来试试 发表于 2021-2-6 18:01

成品有点灰色 不能发的哦
头像被屏蔽
DPP 发表于 2021-2-8 07:36
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 我来试试 发表于 2021-2-8 09:08
DPP 发表于 2021-2-8 07:36
有成品你没接口你也白搭,我抓包了很多接口不知道能发不能 查q绑的

哈哈哈  我一开始的接口也是抓包来的
狂野兔斯基 发表于 2021-2-8 18:12
楼主接口报错呀
 楼主| 我来试试 发表于 2021-2-9 09:28

嗯,接口需要自己加,我这边不能分享接口
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-29 14:44

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表