如何在python中输入html

问题描述:

我想将html文档输入到我的python中。如何在python中输入html

我得到这个错误:

UnicodeDecodeError: 'cp950' codec can't decode byte 0xbb in position
362: illegal multibyte sequence

使用此代码时

from bs4 import BeautifulSoup 

soup = BeautifulSoup(open(xxx.html)) 
print(soup) 

我在做什么错?

+0

[UnicodeDecodeError错误的可能重复:“utf-8”编解码器't解码字节0x9c](https://*.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c) –

您正面临编码/解码问题。
试试这个:

soup = BeautifulSoup(open('xxx.html', encoding='your xxx.html file encoding')) 

您可以通过在文件中搜索“字符集”发现“你xxx.html编码”。
那么,你会得到类似charset=utf-8或后面“=”,“utf-8”或“XXX”其他charset=xxx
,是您xxx.html编码