这个问题肯定是字符的编码错乱导致的。网上也有很多解决方案。我看过的方案很多,最好的就是这个了。

https://www.sohu.com/a/289375951_420744

原因文章说得很清楚,理论也讲得明白。解决方案我录在下面。版权归原作者。

方法一:直接指定res.encoding

import requests
url = "http://search.51job.com"
res = requests.get(url)
res.encoding = "gbk"
html = res.text
print(html)

方法二:通过res.apparent_encoding属性指定

import requests
url = "http://search.51job.com"
res = requests.get(url)
res.encoding = res.apparent_encoding
html = res.text
print(html)

方法三:通过编码、解码的方式

import requests
url = "http://search.51job.com"
res = requests.get(url)
html = res.text.encode('iso-8859-1').decode('gbk')
print(html)

相关文章:

  • 2021-09-11
  • 2022-12-23
  • 2021-11-12
  • 2021-11-15
  • 2022-12-23
  • 2021-12-05
  • 2021-12-25
  • 2021-12-25
猜你喜欢
  • 2021-10-30
  • 2022-12-23
  • 2021-12-25
  • 2021-05-28
  • 2021-12-25
  • 2021-12-25
相关资源
相似解决方案