Skip to content

Instantly share code, notes, and snippets.

@huihut
Created August 28, 2018 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huihut/327895dffa42f3bea87070faf487940d to your computer and use it in GitHub Desktop.
Save huihut/327895dffa42f3bea87070faf487940d to your computer and use it in GitHub Desktop.
Encode Conversion
def encodeConversion(req):
if req.encoding == 'ISO-8859-1':
encodings = requests.utils.get_encodings_from_content(req.text)
if encodings:
encoding = encodings[0]
else:
encoding = req.apparent_encoding
# encode_content = req.content.decode(encoding, 'replace').encode('utf-8', 'replace')
encode_content = req.content.decode(encoding, 'replace') # 如果设置为replace,则会用?取代非法字符;
return encode_content
else:
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment