【问题标题】:Retain the children elements in beautifulSoup python?保留beautifulSoup python中的子元素?
【发布时间】:2014-02-15 17:18:29
【问题描述】:

我的标记为:

<p>Sample text. Click <a href="google.com">Here</a></p>

我想用&lt;span&gt; 替换&lt;p&gt; 标记而不更改标记的子项或文本

【问题讨论】:

    标签: python html beautifulsoup


    【解决方案1】:

    您的任务可以使用replaceWith 完成。您必须复制要用作替换的元素,然后将其作为参数提供给replaceWithdocumentation for replaceWith 非常清楚如何做到这一点。

    无论如何你都可以阅读这个问题How to change tag name with BeautifulSoup?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2020-06-22
      • 2020-07-31
      相关资源
      最近更新 更多