1,py文件代码:

import urllib.request
url = "http://www.douban.com/"
webPage = urllib.request.urlopen(url)
data = webPage.read()
data = data.decode('UTF-8')
print(data)
print(type(webPage))
print(webPage.geturl())
print(webPage.info())
print(webPage.getcode())

2,执行出现字符编码异常:

python, 'gbk' codec can't encode character '\u2122' in position 42161: illegal multibyte sequence

3,解决方案:

#增加字符编码转换
import sys, io
# Change default encoding to utf8  
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-10-05
  • 2021-11-17
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2021-04-14
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案