假设我有一些HTML代码,就像这样(从Markdown或Textile或其他东西生成):
<h1>A header</h1>
<p>Foo</p>
<h2>Another header</h2>
<p>More content</p>
<h2>Different header</h2>
<h1>Another toplevel header
<!-- and so on -->
Run Code Online (Sandbox Code Playgroud)
我怎么能用Python为它生成一个目录?