3 ms·
Htmlq: Like Jq, but for HTML
- jamesmurdza 3y agoNice. I've used Cheerio for this in the past: https://github.com/cheeriojs/cheerio?tab=readme-ov-file#selectors https://github.com/cheeriojs/cheerio?tab=readme-ov-file#sele...
- deleted 3y ago[deleted]
- thriftwy 3y agoTagsoup + xpath for the win. Jq is a nice tool, but...
- sthuck 3y agogreat, now I can stop using regex...
- tangmonk 3y agoWhy not xpath, I just open Chrome Dev tool And click Copy as Xpath
- basilgohar 3y agoThis uses CSS selectors and can be run from the commandline.
- thedookmaster 3y agohere's an alternative I've used in the past: pup https://github.com/ericchiang/pup https://github.com/ericchiang/pup
- deleted 3y ago[deleted]
- lonlazarus 3y agoYou should’ve called it jq.select it’d be both appropriate and very confusing.
- deleted 3y ago[deleted]
- sylware 3y agoIsn'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".
- Nullabillity 3y agoThat'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 https://github.com/servo/html5ever
- sylware 3y agoSo 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.
- Nullabillity 3y agoIt's part of the HTML standard itself: https://html.spec.whatwg.org/multipage/parsing.html#parsing https://html.spec.whatwg.org/multipage/parsing.html#parsing
- sylware 3y agoyep, that's the right one: completely brain damaged. I guess if I ever write an HTML parser (noscript), I'll do it xml like.
- ape4 3y agoCould be implemented by processing the output of jq