mirror of
https://github.com/LibraHp/GetQzonehistory.git
synced 2025-01-01 09:39:55 +00:00
Fix no attribute 'encoding' error and add fake-useragent
Signed-off-by: zlaazlaa <2889827787@qq.com>
This commit is contained in:
parent
0ec3b3a3b9
commit
9bb89c9924
15
main.py
15
main.py
@ -17,7 +17,9 @@ import traceback
|
|||||||
import dateparser
|
import dateparser
|
||||||
import hashlib
|
import hashlib
|
||||||
import copy
|
import copy
|
||||||
|
from fake_useragent import UserAgent
|
||||||
|
|
||||||
|
ua = UserAgent()
|
||||||
# 程序版本
|
# 程序版本
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
|
||||||
@ -66,7 +68,7 @@ headers = {
|
|||||||
'sec-fetch-user': '?1',
|
'sec-fetch-user': '?1',
|
||||||
'upgrade-insecure-requests': '1',
|
'upgrade-insecure-requests': '1',
|
||||||
# Temporarily fix waf issues
|
# Temporarily fix waf issues
|
||||||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15',
|
'user-agent': ua.random,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1050,9 +1052,9 @@ def main(page: ft.Page):
|
|||||||
|
|
||||||
def get_message(start, count):
|
def get_message(start, count):
|
||||||
while True:
|
while True:
|
||||||
message_content = get_message_unsafe(start, count)
|
mc = get_message_unsafe(start, count)
|
||||||
if message_content.encoding.lower() == 'utf-8':
|
if isinstance(mc, requests.Response) and mc.status_code == 200 and mc.encoding.lower() == 'utf-8':
|
||||||
return message_content
|
return mc
|
||||||
|
|
||||||
def get_message_unsafe(start, count):
|
def get_message_unsafe(start, count):
|
||||||
cookies = page.session.get("user_cookies")
|
cookies = page.session.get("user_cookies")
|
||||||
@ -1086,10 +1088,9 @@ def main(page: ft.Page):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
timeout=(5, 10) # 设置连接超时为5秒,读取超时为10秒
|
timeout=(5, 10) # 设置连接超时为5秒,读取超时为10秒
|
||||||
)
|
)
|
||||||
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return 'None'
|
return None
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
def get_message_count():
|
def get_message_count():
|
||||||
total = 10
|
total = 10
|
||||||
|
@ -3,4 +3,5 @@ flet==0.24.1
|
|||||||
pandas==2.2.3
|
pandas==2.2.3
|
||||||
Requests==2.31.0
|
Requests==2.31.0
|
||||||
openpyxl==3.1.5
|
openpyxl==3.1.5
|
||||||
dateparser==1.2.0
|
dateparser==1.2.0
|
||||||
|
fake-useragent
|
Loading…
Reference in New Issue
Block a user