![]() |
纯真的包子 · 利用 HTML 模板自定义用户界面 - ...· 2 月前 · |
![]() |
健身的水煮鱼 · select function ...· 4 月前 · |
![]() |
时尚的楼房 · 全文本搜索会对结果进行排序-掘金· 1 年前 · |
![]() |
路过的茴香 · FastChat/vicuna ...· 1 年前 · |
我的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())
![]() |
时尚的楼房 · 全文本搜索会对结果进行排序-掘金 1 年前 |