I'm a beginner programmer so this is probably a trivial question: I have a .html file with a deeply nested unordered list. How can I copy for example the first 4 nesting levels into a new empty .html file in Python? Do I need BeautifulSoup for this? For better illustration here is the code for the display effect in Javascript:
function nestless(root, selector, level) {
var use = root;
for (var i = 0; i <= level; i++) {
use += ' ' + selector;
}
$(use).remove();
}
Here I would use:
nestless('#root', 'ul', 4);
It seems that my original question is badly written and difficult to parse, I'm sorry for that. The .html files are not really websites, but rather manually written text documents in a html editor and saved in .html. They contain nothing that couldn't be written with a LaTeX editor.
For example if I wanted to reduce this list list to the first 2 levels:
- A
- B
- C
- D
- E
- F
- G
to
- A
- B
- C
- D
- G
From my own research there are .html parsers via CSS selectors in BeautifulSoup+soupselect, PyQuery or lxml, but I'm not sure what's the easiest way to proceed or where to start reading.