Python beautifulsoup如何去除自己不想要的Dom子节点?

wylc123 1年前 ⋅ 292 阅读

decompose 相当于 DOM API 的 remove:

root = bs('<html><body><p><a></a></p></body></html>', 'lxml')
root.p.decompose()
root
# <html><body></body></html>

而 clear 相当于 API 中的 empty:

root = bs('<html><body><p><a></a></p></body></html>', 'lxml')
root.p.clear()
root
# <html><body><p></p></body></html>

相关文章推荐
  • 该目录下还没有内容!

全部评论: 0

    我有话说: