3 ms·
I wrote a simple HTML parser for a web crawler many years ago. What it did was just record each opening and closing tag, and created a list of (open_pos, end_po
by captainmuon 9y ago
I wrote a simple HTML parser for a web crawler many years ago. What it did was just record each opening and closing tag, and created a list of (open_pos, end_pos) spans. This was much more general than building a tree, and had no problems with really malformed HTML (such as overlapping tags <b>Bold <i>Both</b> Italic</i>).
Funnily, this wouldn't work anymore. The efforts to fix HTML have made it even more complicated. Now browsers insert a lot of fictious tags if you nest things improperly, and you have to simulate that.