From 4a07a2a673fdd7c2ca9a0b0f7ac8c23517325bcc Mon Sep 17 00:00:00 2001 From: zlaazlaa <2889827787@qq.com> Date: Tue, 12 Nov 2024 00:33:25 +0800 Subject: [PATCH] Add fake-useragent Signed-off-by: zlaazlaa <2889827787@qq.com> --- requirements.txt | 1 + util/RequestUtil.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8b8e599..0e99343 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ pyarrow==14.0.1 openpyxl==3.1.2 pyzbar~=0.1.9 qrcode~=7.4.2 +fake-useragent \ No newline at end of file diff --git a/util/RequestUtil.py b/util/RequestUtil.py index be3b517..a3d7b3e 100644 --- a/util/RequestUtil.py +++ b/util/RequestUtil.py @@ -3,7 +3,9 @@ from tqdm import tqdm import util.LoginUtil as Login import requests import json +from fake_useragent import UserAgent +ua = UserAgent() # 登陆后获取到的cookies cookies = Login.cookie() # 获取g_tk @@ -26,8 +28,7 @@ headers = { 'sec-fetch-site': 'none', 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 ' - 'Safari/537.36 Edg/121.0.0.0', + 'user-agent': ua.safari, }