From 36c734ca9e0d7d8c90c5317b95cc4de701ffbce6 Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 6 Jun 2021 05:57:22 +0800 Subject: [PATCH] upgrade User-Agent string to current Chrome version --- ADC_function.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ADC_function.py b/ADC_function.py index 87a70cc..6593006 100644 --- a/ADC_function.py +++ b/ADC_function.py @@ -30,6 +30,8 @@ def getXpathSingle(htmlcode, xpath): return result1 +G_USER_AGENT = r'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36' + # 网页请求核心 def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None): verify = config.Config().cacert_file() @@ -37,8 +39,7 @@ def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None) errors = "" if ua is None: - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36"} # noqa + headers = {"User-Agent": G_USER_AGENT} # noqa else: headers = {"User-Agent": ua} @@ -72,8 +73,7 @@ def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None) def post_html(url: str, query: dict, headers: dict = None) -> requests.Response: configProxy = config.Config().proxy() errors = "" - headers_ua = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36"} + headers_ua = {"User-Agent": G_USER_AGENT} if headers is None: headers = headers_ua else: