Merge pull request #512 from lededev/chrome-agent

upgrade User-Agent string to current Chrome version
This commit is contained in:
Yoshiko2
2021-06-06 17:55:58 +08:00
committed by GitHub

View File

@@ -30,6 +30,8 @@ def getXpathSingle(htmlcode, xpath):
return result1 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): def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None):
verify = config.Config().cacert_file() verify = config.Config().cacert_file()
@@ -37,8 +39,7 @@ def get_html(url, cookies: dict = None, ua: str = None, return_type: str = None)
errors = "" errors = ""
if ua is None: if ua is None:
headers = { headers = {"User-Agent": G_USER_AGENT} # noqa
"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
else: else:
headers = {"User-Agent": ua} 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: def post_html(url: str, query: dict, headers: dict = None) -> requests.Response:
configProxy = config.Config().proxy() configProxy = config.Config().proxy()
errors = "" errors = ""
headers_ua = { headers_ua = {"User-Agent": G_USER_AGENT}
"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"}
if headers is None: if headers is None:
headers = headers_ua headers = headers_ua
else: else: