UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb3 in position
爬虫 print(response.read().decode(“utf-8”))报错信息
和讯网用gb18030编码
import urllib.request
import urllib.parse
#把请求对象包装成浏览器
url = “http://stockdata.stock.hexun.com/zrbg/”
headers = {
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.57”
}
req = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(req)
print(response.read().decode(“gb18030”))