16 comments

[ 2.5 ms ] story [ 40.8 ms ] thread
(comment deleted)
Tagsoup + xpath for the win.

Jq is a nice tool, but...

great, now I can stop using regex...
Why not xpath, I just open Chrome Dev tool And click Copy as Xpath
This uses CSS selectors and can be run from the commandline.
You should’ve called it jq.select it’d be both appropriate and very confusing.
(comment deleted)
(comment deleted)
Isn't parsing html not like xml? I recall you need a special and weird algorithm to parse html properly. Was a long time ago though, dunno if that was "fixed".
That's largely correct. HTML5 changed the status quo from "eh, it should be XML but every browser applies its own weird hacks" to "well, the hacks still apply but at least they're defined by the standard now". The proper solution would have been XHTML, but we can't have nice things.

This seems to use html5ever[0], which is a "proper" HTML browser also used by the Servo browser.

[0]: https://github.com/servo/html5ever

So there is a rigorous definition of a brain damage parser for HTML.

Where is this defined already? Does it have a name?

That said, I recall clearly how the major browsers did sabotage xhtml, at the time (a decade ago). The middle-ground would be to go xml-like parsing but for html, namely without xml kludge.

Could be implemented by processing the output of jq