from urllib.request import urlopen
import  chardet
response=urlopen(url,timeout=3)
html_byte=response.read()
chardit1 = chardet.detect(html_byte)
file = open(PROJECT_NAME + '/' + str(ALLNUM) + '.html', 'wb')          html_string=html_byte.decode(chardit1['encoding']).encode('utf-8')
file.write(html_string)
file.close()

利用到了chardet中的detect方法,获取chardit1[‘encoding’]探知是何种类型的编码,对其进行译码,再编码。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐