Created
August 28, 2018 15:42
-
-
Save huihut/327895dffa42f3bea87070faf487940d to your computer and use it in GitHub Desktop.
Encode Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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