mirror of
https://github.com/LibraHp/GetQzonehistory.git
synced 2025-02-23 05:49:07 +00:00
添加获取说说总量的逻辑
This commit is contained in:
parent
1bf7727321
commit
36d1434498
6
main.py
6
main.py
@ -30,13 +30,13 @@ if __name__ == '__main__':
|
|||||||
print(f"登录失败:请重新登录,错误信息:{str(e)}")
|
print(f"登录失败:请重新登录,错误信息:{str(e)}")
|
||||||
exit(0)
|
exit(0)
|
||||||
texts = []
|
texts = []
|
||||||
|
count = Request.get_message_count()
|
||||||
try:
|
try:
|
||||||
# 注册信号处理函数
|
# 注册信号处理函数
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
signal.signal(signal.SIGTERM, signal_handler)
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
|
||||||
for i in trange(1000, desc='Progress', unit='100条'):
|
for i in trange(int(count / 100) + 1, desc='Progress', unit='100条'):
|
||||||
message = Request.get_message(i * 100, 100).content.decode('utf-8')
|
message = Request.get_message(i * 100, 100).content.decode('utf-8')
|
||||||
html = Tools.process_old_html(message)
|
html = Tools.process_old_html(message)
|
||||||
if "li" not in html:
|
if "li" not in html:
|
||||||
@ -50,7 +50,7 @@ if __name__ == '__main__':
|
|||||||
if time_element is not None and text_element is not None:
|
if time_element is not None and text_element is not None:
|
||||||
time = time_element.get_text().replace('\xa0', ' ')
|
time = time_element.get_text().replace('\xa0', ' ')
|
||||||
text = text_element.get_text().replace('\xa0', ' ')
|
text = text_element.get_text().replace('\xa0', ' ')
|
||||||
if text not in [sublist[1] for sublist in texts] and time is not None and text is not None:
|
if text not in [sublist[1] for sublist in texts]:
|
||||||
texts.append([time, text])
|
texts.append([time, text])
|
||||||
|
|
||||||
if len(texts) > 0:
|
if len(texts) > 0:
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import re
|
import re
|
||||||
|
from tqdm import tqdm
|
||||||
import util.LoginUtil as Login
|
import util.LoginUtil as Login
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# 登陆后获取到的cookies
|
# 登陆后获取到的cookies
|
||||||
cookies = Login.cookie()
|
cookies = Login.cookie()
|
||||||
# 获取g_tk
|
# 获取g_tk
|
||||||
@ -63,3 +64,22 @@ def get_login_user_info():
|
|||||||
info = info.strip().lstrip('portraitCallBack(').rstrip(');')
|
info = info.strip().lstrip('portraitCallBack(').rstrip(');')
|
||||||
info = json.loads(info)
|
info = json.loads(info)
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
def get_message_count():
|
||||||
|
# 初始的总量范围
|
||||||
|
lower_bound = 0
|
||||||
|
upper_bound = 100000 # 假设最大总量为1000000
|
||||||
|
total = upper_bound // 2 # 初始的总量为上下界的中间值
|
||||||
|
with tqdm(desc="正在获取消息列表数量...") as pbar:
|
||||||
|
while lower_bound <= upper_bound:
|
||||||
|
response = get_message(total, 100)
|
||||||
|
if "li" in response.text:
|
||||||
|
# 请求成功,总量应该在当前总量的右侧
|
||||||
|
lower_bound = total + 1
|
||||||
|
else:
|
||||||
|
# 请求失败,总量应该在当前总量的左侧
|
||||||
|
upper_bound = total - 1
|
||||||
|
total = (lower_bound + upper_bound) // 2 # 更新总量为新的中间值
|
||||||
|
pbar.update(1)
|
||||||
|
return total
|
||||||
|
Loading…
Reference in New Issue
Block a user