response = urllib.request.urlopen(url)
html= response.read().decode(“utf-8”)
利用上述语句爬取网页时,不少网站会引发UnicodeDecodeError的错误。
解决方法:
1.html= response.read().decode(“utf-8”, “ignore”)
爬取的页面中汉字变乱码,但不影响英文(如网址)的爬取。
2.html= response.read().decode(“gbk”)
目前没有发现遗留问题。
Python错误:UnicodeDecodeError: 'utf-8' codec can't decode byte...
最新推荐文章于 2022-08-31 00:43:13 发布