修复不能获取content-type时会出现的问题

This commit is contained in:
g1879 2020-12-24 17:07:17 +08:00
parent af2f2e2f45
commit 09db942090

View File

@ -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'<meta.*?charset=[ \\\'"]*([^"\\\' />]+).*?>', r.content)
if re_result: