Re:Htmlq: like jq, but for html
by purplecats on Tuesday September 07, 2021 @03:59AM
(#28442181)
brilliant. does this spin up a heavy DOM implementation in the background or do something lighter such as regexp?
[ Parent
| on HN ]
You can't parse html with regular expressions :)
https://stackoverflow.com/questions/1732348/regex-match-open...
"Oh Yes You Can Use Regexes to Parse HTML!"
Yeah, if you allow yourself some Perl to help you with those parts that regexes can't handle...
Technically correct, but did you see the regex he uses? It spans 82 lines...
And the obligitory caveat from the comments:
> While arbitrary HTML with only a regex is impossible, it's sometimes appropriate to use them for parsing a limited, known set of HTML.
The emphasis here is on "known". The tool is general purpose (i.e. handling unknown HTML) so using regexes would be ill-advised.
Looks like it uses servos html5ever (through kuchiki), so no DOM representation.
Re:Htmlq: like jq, but for html
by chrismorgan on Tuesday September 07, 2021 @04:23AM
(#28442354)
Kuchiki materialises what they call a “DOM-like tree”. I’d consider it a DOM tree, myself, despite the differences in precise API.
But it’s not using a full browser to back it, which I suspect is what’s really being asked.
It looks to be using html5ever to parse the HTML, similar to something like BeautifulSoup in Python.
Re:Htmlq: like jq, but for html
by delusional on Tuesday September 07, 2021 @04:03AM
(#28442210)
The source is right there. You can read it. It uses html5ever (part of the servo project).
You can’t parse HTML with regexps. It’s not a regular language.
Re:Htmlq: like jq, but for html
by underdeserver on Tuesday September 07, 2021 @04:03AM
(#28442213)