3 from bs4
import BeautifulSoup
7 # Accept filename as user input
9 if (argc
< 2): raise Exception
10 fileName
= sys
.argv
[1];
12 # Construct a DOM object
13 soup
= BeautifulSoup(open(fileName
), "lxml")
15 # Get just the table of contents from the index page
16 toc
= soup
.find("ul","ChildLinks").extract()
18 # Retain only part and chapter titles
19 for sctn
in toc
.select("li > ul > li > ul"):
27 toc
['class'] = "manual-toc"
29 # Print cleaned up markup to stdout
30 print( toc
.prettify(formatter
="html") )