From e1daebd35059c41e32a115327e57fab1c031655b Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 17 Jul 2023 17:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=E5=BD=93?= =?UTF-8?q?=E7=BD=91=E7=AB=99headers=E4=B8=8D=E8=A7=84=E8=8C=83=E6=97=B6?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E7=BC=96=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/session_page.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index b6c1193..738d9a4 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -7,7 +7,7 @@ from re import search from time import sleep from urllib.parse import urlparse -from requests import Session, Response +from requests import Session from requests.structures import CaseInsensitiveDict from tldextract import extract @@ -305,15 +305,17 @@ class SessionPage(BasePage): return r, f'状态码:{r.status_code}' -def check_headers(kwargs, headers, arg) -> bool: +def check_headers(kwargs, headers, arg): """检查kwargs或headers中是否有arg所示属性""" return arg in kwargs['headers'] or arg in headers -def set_charset(response) -> Response: +def set_charset(response): """设置Response对象的编码""" # 在headers中获取编码 content_type = response.headers.get('content-type', '').lower() + if not content_type.endswith(';'): + content_type += ';' charset = search(r'charset[=: ]*(.*)?;', content_type) if charset: