|
|
唠叨的棒棒糖 · 【MySQL】order ...· 2 年前 · |
|
|
逃课的手套 · java调用shell - OSCHINA ...· 3 年前 · |
|
|
刚毅的刺猬 · ionic2/3 ngClass ...· 3 年前 · |
|
|
性感的灯泡 · 程序运行慢?你怕是写的假 Python - ...· 3 年前 · |
我的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())