我的html内容如下:
html = <div>new notes</div><div><ol><li>kssd</li></ol><ul><li>cds</li><li>dsdsk</li></ul><font color=\"#66717b\">ndsmnd</font></div>
当我将上面的表达式转换为字符串时,它会引发错误。
html_str = str(html)
我可以看到“在这里已经转义了。我需要替换/”和//“然后转换成字符串吗?”
发布于 2022-11-18 05:06:05
我认为您需要使用get_text()
from bs4 import BeautifulSoup
htmlvar = BeautifulSoup(html)
print(htmlvar.get_text())
发布于 2022-11-18 05:58:33
你可以试试这个:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')
print(soup.prettify())
tag = soup.html
string = str(tag)
print(string)
https://stackoverflow.com/questions/74485126
复制相似问题