2024-02-14 08:58:07 +00:00
|
|
|
|
import re
|
2024-02-14 13:15:17 +00:00
|
|
|
|
from tqdm import tqdm
|
2024-02-13 05:45:57 +00:00
|
|
|
|
import util.LoginUtil as Login
|
|
|
|
|
import requests
|
2024-02-13 12:47:18 +00:00
|
|
|
|
import json
|
2024-11-11 16:33:25 +00:00
|
|
|
|
from fake_useragent import UserAgent
|
2024-02-14 13:15:17 +00:00
|
|
|
|
|
2024-11-11 16:33:25 +00:00
|
|
|
|
ua = UserAgent()
|
2024-02-13 05:45:57 +00:00
|
|
|
|
# 登陆后获取到的cookies
|
|
|
|
|
cookies = Login.cookie()
|
|
|
|
|
# 获取g_tk
|
|
|
|
|
g_tk = Login.bkn(cookies.get('p_skey'))
|
|
|
|
|
# 获取uin
|
2024-02-14 08:58:07 +00:00
|
|
|
|
uin = re.sub(r'o0*', '', cookies.get('uin'))
|
2024-02-13 05:45:57 +00:00
|
|
|
|
# 全局header
|
|
|
|
|
headers = {
|
|
|
|
|
'authority': 'user.qzone.qq.com',
|
|
|
|
|
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
|
|
|
|
|
'application/signed-exchange;v=b3;q=0.7',
|
|
|
|
|
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
|
|
|
'cache-control': 'no-cache',
|
|
|
|
|
'pragma': 'no-cache',
|
|
|
|
|
'sec-ch-ua': '"Not A(Brand";v="99", "Microsoft Edge";v="121", "Chromium";v="121"',
|
|
|
|
|
'sec-ch-ua-mobile': '?0',
|
|
|
|
|
'sec-ch-ua-platform': '"Windows"',
|
|
|
|
|
'sec-fetch-dest': 'document',
|
|
|
|
|
'sec-fetch-mode': 'navigate',
|
|
|
|
|
'sec-fetch-site': 'none',
|
|
|
|
|
'sec-fetch-user': '?1',
|
|
|
|
|
'upgrade-insecure-requests': '1',
|
2024-11-11 16:33:25 +00:00
|
|
|
|
'user-agent': ua.safari,
|
2024-02-13 05:45:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取历史消息列表
|
|
|
|
|
def get_message(start, count):
|
|
|
|
|
params = {
|
|
|
|
|
'uin': uin,
|
|
|
|
|
'begin_time': '0',
|
|
|
|
|
'end_time': '0',
|
|
|
|
|
'getappnotification': '1',
|
|
|
|
|
'getnotifi': '1',
|
|
|
|
|
'has_get_key': '0',
|
|
|
|
|
'offset': start,
|
|
|
|
|
'set': '0',
|
|
|
|
|
'count': count,
|
|
|
|
|
'useutf8': '1',
|
|
|
|
|
'outputhtmlfeed': '1',
|
|
|
|
|
'scope': '1',
|
2024-02-13 10:22:44 +00:00
|
|
|
|
'format': 'jsonp',
|
2024-02-13 05:45:57 +00:00
|
|
|
|
'g_tk': [
|
|
|
|
|
g_tk,
|
|
|
|
|
g_tk,
|
|
|
|
|
],
|
|
|
|
|
}
|
2024-09-11 15:50:26 +00:00
|
|
|
|
|
2024-09-10 07:54:17 +00:00
|
|
|
|
try:
|
|
|
|
|
response = requests.get(
|
|
|
|
|
'https://user.qzone.qq.com/proxy/domain/ic2.qzone.qq.com/cgi-bin/feeds/feeds2_html_pav_all',
|
|
|
|
|
params=params,
|
|
|
|
|
cookies=cookies,
|
|
|
|
|
headers=headers,
|
|
|
|
|
timeout=(5, 10) # 设置连接超时为5秒,读取超时为10秒
|
|
|
|
|
)
|
|
|
|
|
except requests.Timeout:
|
|
|
|
|
print("请求超时")
|
|
|
|
|
return None
|
2024-09-11 15:50:26 +00:00
|
|
|
|
|
2024-02-13 05:45:57 +00:00
|
|
|
|
return response
|
2024-02-13 12:47:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_login_user_info():
|
|
|
|
|
response = requests.get('https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=' + str(g_tk) + '&uins=' + uin,
|
|
|
|
|
headers=headers, cookies=cookies)
|
|
|
|
|
info = response.content.decode('GBK')
|
|
|
|
|
info = info.strip().lstrip('portraitCallBack(').rstrip(');')
|
|
|
|
|
info = json.loads(info)
|
|
|
|
|
return info
|
2024-02-14 13:15:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_message_count():
|
|
|
|
|
# 初始的总量范围
|
|
|
|
|
lower_bound = 0
|
2024-09-13 02:40:35 +00:00
|
|
|
|
upper_bound = 10000000 # 假设最大总量为1000000
|
2024-02-14 13:15:17 +00:00
|
|
|
|
total = upper_bound // 2 # 初始的总量为上下界的中间值
|
|
|
|
|
with tqdm(desc="正在获取消息列表数量...") as pbar:
|
|
|
|
|
while lower_bound <= upper_bound:
|
2024-09-11 15:50:26 +00:00
|
|
|
|
try:
|
|
|
|
|
response = get_message(total, 100)
|
|
|
|
|
|
|
|
|
|
if response and hasattr(response, 'text'):
|
|
|
|
|
if "li" in response.text:
|
|
|
|
|
lower_bound = total + 1
|
|
|
|
|
else:
|
|
|
|
|
upper_bound = total - 1
|
|
|
|
|
else:
|
|
|
|
|
print(f"无效的响应对象: {response}")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"请求发生异常: {e}")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
total = (lower_bound + upper_bound) // 2
|
2024-02-14 13:15:17 +00:00
|
|
|
|
pbar.update(1)
|
2024-09-11 15:50:26 +00:00
|
|
|
|
|
2024-02-14 13:15:17 +00:00
|
|
|
|
return total
|