将网页get到之后输入文本出现UnicodeEncodeError: 'ascii' codec can't encode characters错误

f = open('re.txt', 'w')
url = "http://www.baidu.com"
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encodingprint(r.text)
f.write(r_text)
f.close()

解决办法是

  r_text = r.text.encode('UTF-8')

加入这一行

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-01-01
  • 2021-08-14
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2022-12-23
  • 2022-01-24
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案