I'm looking to somewhat generate a "table of contents" of sorts with BeautifulSoup. I've tried extracting the h1, h2, and h3 tags and building a string accordingly, but I'm struggling because I retain the tag content. I'm also struggling in general to get the format correct. Here's what I want.
Let's say I have a file, test.html
<h1>First Part<h1>
<h2>First sub Part<h2>
<h3>First sub sub part<h3>
<h1>Second Part<h1>
<h2>Second sub Part<h2>
<h3>Second sub sub part<h3>
Then, I want to end up generating the HTML that would give me this:
- First part
- First sub part
- First sub sub part
- First sub part
The bullet's dont look great because of Stack's formatting (there may be functionality for this, but I'm not aware of how to use it), but you get the gist. Any ideas?
Thanks!