From 09db94209085605de9295cd7cf58604586ee45f2 Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 24 Dec 2020 17:07:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E8=83=BD=E8=8E=B7?= =?UTF-8?q?=E5=8F=96content-type=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 060e50d..7fc2223 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -520,14 +520,14 @@ class SessionPage(object): else: # ----------------获取并设置编码开始----------------- # 在headers中获取编码 - content_type = r.headers.get('content-type').lower() + content_type = r.headers.get('content-type', '').lower() charset = re.search(r'charset[=: ]*(.*)?[;]', content_type) if charset: r.encoding = charset.group(1) # 在headers中获取不到编码,且如果是网页 - elif content_type.replace(' ', '').lower().startswith('text/html'): + elif content_type.replace(' ', '').startswith('text/html'): re_result = re_SEARCH(b']+).*?>', r.content) if re_result: