【问题标题】:How to convert HTML tag into string using python如何使用python将HTML标签转换成字符串
【发布时间】:2022-11-18 13:18:25
【问题描述】:

我的 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)

我可以看到 " 已经在这里转义了。我需要用 //" 替换 /" 然后转换为字符串吗?

【问题讨论】:

    标签: python html python-3.x python-2.7


    【解决方案1】:

    我认为你需要使用获取文本()

    from bs4 import BeautifulSoup
    htmlvar = BeautifulSoup(html)
    print(htmlvar.get_text())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-09
      • 2013-08-14
      • 1970-01-01
      • 2022-01-19
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多