【发布时间】:2012-10-09 04:27:59
【问题描述】:
我正在使用 BeautifulSoup 进行一些 HTML 清理。 Python 和 BeautifulSoup 的新手。根据我在 Stackoverflow 其他地方找到的答案,我已经正确删除了如下标签:
[s.extract() for s in soup('script')]
但是如何删除内联样式呢?例如:
<p class="author" id="author_id" name="author_name" style="color:red;">Text</p>
<img class="some_image" href="somewhere.com">
应该变成:
<p>Text</p>
<img href="somewhere.com">
如何删除所有元素的内联class、id、name&style属性?
我可以找到其他类似问题的答案,我可以找到所有提到的使用 CSS 解析器来处理这个问题,而不是 BeautifulSoup,但由于任务只是删除而不是操纵属性,并且是所有标签的一揽子规则,我是希望能在 BeautifulSoup 中找到一种方法。
【问题讨论】:
标签: python css beautifulsoup inline