【发布时间】:2020-01-27 13:11:48
【问题描述】:
我正在编写发送请求和获取网站响应以及解析它的内容的函数...... 但是当我向波斯网站发送请求时,它无法解码它的内容
def gather_links(page_url):
html_string = ''
try:
response = urlopen(page_url)
if 'text/html' in response.getheader('Content-Type'):
html_bytes = response.read()
html_string = html_bytes.decode("utf-8")
except Exception as e:
print(str(e))
显示此错误,例如 https://www.entekhab.ir/:
'utf-8' 编解码器无法解码位置 1 中的字节 0x8b:无效的起始字节
如何更改解码此类网站的代码?
【问题讨论】:
标签: python gzip decoding transfer-encoding