gpt4 book ai didi

python - BeautifulSoup' 没有属性 'HTML_ENTITIES

转载 作者:太空狗 更新时间:2023-10-30 02:48:43 28 4
gpt4 key购买 nike

我最近在 Windows 机器上将 BeautifulSoup 从 3.0 版升级到 4.1 版。

我现在遇到一个奇怪的错误:

File "C:\path\to\myscript.py", line 23
0, in soupify
return BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
AttributeError: type object 'BeautifulSoup' has no attribute 'HTML_ENTITIES'

下面是导致抛出异常的代码片段:

def soupify(html):
return BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)

BS 的文档没有提及构造函数签名如何从 v3 更改为 v4。我该如何解决这个问题?

最佳答案

An incoming HTML or XML entity is always converted into the corresponding Unicode character. Beautiful Soup 3 had a number of overlapping ways of dealing with entities, which have been removed. The BeautifulSoup constructor no longer recognizes the smartQuotesTo or convertEntities arguments. (Unicode, Dammit still has smart_quotes_to, but its default is now to turn smart quotes into Unicode.)

If you want to turn those Unicode characters back into HTML entities on output, rather than turning them into UTF-8 characters, you need to use an output formatter.

来源:http://www.crummy.com/software/BeautifulSoup/bs4/doc/#entities

关于python - BeautifulSoup' 没有属性 'HTML_ENTITIES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11856011/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com