Merge pull request #166 from ThinkerWen/main

fix: utf-8 decode error close #156 #157 #158 #161
This commit is contained in:
LibraHp_0928 2024-11-14 20:31:30 +08:00 committed by GitHub
commit e7228ebb0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -14,6 +14,7 @@ from tqdm import trange, tqdm
import requests import requests
import time import time
import platform import platform
import chardet
texts = list() texts = list()
all_friends = list() all_friends = list()
@ -237,7 +238,9 @@ if __name__ == '__main__':
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(int(count / 100) + 1, 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') content_bytes = Request.get_message(i * 100, 100).content
detected_encoding = chardet.detect(content_bytes)['encoding']
message = content_bytes.decode(detected_encoding if detected_encoding else "utf-8")
time.sleep(0.2) time.sleep(0.2)
html = Tools.process_old_html(message) html = Tools.process_old_html(message)
if "li" not in html: if "li" not in html:

View File

@ -6,5 +6,6 @@ Pillow==11.0.0
pyarrow==18.0.0 pyarrow==18.0.0
openpyxl==3.1.5 openpyxl==3.1.5
pyzbar~=0.1.9 pyzbar~=0.1.9
qrcode~=8.0 qrcode~=7.4.2
fake-useragent fake-useragent~=1.5.1
chardet~=5.2.0