mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
修复不能获取content-type时会出现的问题
This commit is contained in:
parent
af2f2e2f45
commit
09db942090
@ -520,14 +520,14 @@ class SessionPage(object):
|
|||||||
else:
|
else:
|
||||||
# ----------------获取并设置编码开始-----------------
|
# ----------------获取并设置编码开始-----------------
|
||||||
# 在headers中获取编码
|
# 在headers中获取编码
|
||||||
content_type = r.headers.get('content-type').lower()
|
content_type = r.headers.get('content-type', '').lower()
|
||||||
charset = re.search(r'charset[=: ]*(.*)?[;]', content_type)
|
charset = re.search(r'charset[=: ]*(.*)?[;]', content_type)
|
||||||
|
|
||||||
if charset:
|
if charset:
|
||||||
r.encoding = charset.group(1)
|
r.encoding = charset.group(1)
|
||||||
|
|
||||||
# 在headers中获取不到编码,且如果是网页
|
# 在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)
|
re_result = re_SEARCH(b'<meta.*?charset=[ \\\'"]*([^"\\\' />]+).*?>', r.content)
|
||||||
|
|
||||||
if re_result:
|
if re_result:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user