【发布时间】:2016-03-14 14:16:26
【问题描述】:
是否有一种递归方法可以使用 Python ElementTree 减少 HTLM 树中的所有标题级别? 在下面的示例中,h1 将变为 h2,因此对于其他标题。
#! /usr/bin/env python
import html5lib
import xml.etree.ElementTree as ET
headings = '''<h1>Title</h1>
<h2>Sub Title</h2>
<h3>Sub sub title 1</h3>
<h3>Sub sub title 2</h3>
<h4>Sub sub sub title<h4>
<h3>Sub sub title</h3>
'''
tree = html5lib.parse(headings, namespaceHTMLElements=False)
【问题讨论】:
标签: python html xml elementtree