项目场景:python抓取数据时报错
提示:codec can’t decode byte 0xa1 in position 246: invalid start byte
类似的问题都可以解决
问题描述:‘utf-8’ codec can’t decode byte 0xa1 in position 246: invalid start byte
提示:这里描述项目中遇到的问题:
例如:数据传输过程中数据不时出现丢失的情况,偶尔会丢失一部分数据
APP 中接收数据代码:
try:
response = urllib.request.urlopen(request)
html = response.read().decode("utf-8")
print(html)
except urllib.error.URLError as e:
if hasattr(e, "code"):
print(e.code)
if hasattr(e, "reason"):
print(e.reason)
return html
原因分析:
将你的编码改成你爬取的那个网站的格式
解决方案:
例如进入目标网站的开发者模式查看编码
改正后即可成功
结束:有什么问题可以留言!!!!