The emergence of Chinese coding solutions garbled when crawling pages of questions

 

See website coding is utf-8, but there have been garbled, feeling certainly not use the Chinese utf-8 encoded form of

 

import requests

 

r = requests.get('http://www.baidu.com/')

print (type(r))     #  <class 'requests.models.Response'>

print (r.encoding)    # ISO-8859-1

print (r.apparent_encoding) # GB2312 r.apparent_encoding is by analyzing the content of the coding

print ((r.text.encode (r.encoding) .decode (r.apparent_encoding))) # Returns the hash code is not

 

Guess you like

Origin www.cnblogs.com/trunkslisa/p/10945153.html