3 ms·
Markup Language Operations in Nim to extract and remove HTML elements
- emmanueloga_ 5y agoFrom a quick look it seems to use regular expressions to parse XML, so... see [1]. From a quick search it looks like nim includes XML parsing on its std [2]. 1: https://stackoverflow.com/questions/8577060/why-is-it-such-a-bad-idea-to-parse-xml-with-regex https://stackoverflow.com/questions/8577060/why-is-it-such-a... 2: https://nim-lang.org/docs/parsexml.html https://nim-lang.org/docs/parsexml.html
- twiss 5y agoAlso, HTML has its own, well-defined parsing algorithm [1], which is incompatible with XML, e.g. see [2]. Anything that claims to be able to parse both HTML and XML, without knowing which one it is, is lying. 1: https://html.spec.whatwg.org/multipage/parsing.html https://html.spec.whatwg.org/multipage/parsing.html 2: https://news.ycombinator.com/item?id=30600589 https://news.ycombinator.com/item?id=30600589
- deleted 5y ago[deleted]
- Shared404 5y agoNot sure how I didn't know there was already a defined algorithm for parsing HTML. I may try implementing that at some point - I've always been interested, but also got burned out as soon as I tried to work out a viable algorithm. Reason #255 to look things up right away.
- emmanueloga_ 5y agooops... I saw a markup parser and automatically thought XML, but you are right! HTML is actually a whole different beast! As it turns out, seems like nim also has an html parser [1], but I'm guessing something like Google's gumbo [2] could be more reliable, but you would have to write bindings for nim. 1: https://nim-lang.org/docs/htmlparser.html https://nim-lang.org/docs/htmlparser.html 2: https://github.com/google/gumbo-parser https://github.com/google/gumbo-parser