【问题标题】:How to input html in python如何在python中输入html
【发布时间】:2018-03-04 17:12:43
【问题描述】:

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

我收到此错误:

UnicodeDecodeError:“cp950”编解码器无法解码位置中的字节 0xbb
362: 非法多字节序列

使用此代码时:

from bs4 import BeautifulSoup

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

我做错了什么?

【问题讨论】:

标签: python beautifulsoup


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多