4 ms·
Google "haskell parse html", the first hit is a tutorial, the second hit the TagSoup library on hackage.
by mb2100 11y ago
Google "haskell parse html", the first hit is a tutorial, the second hit the TagSoup library on hackage.
- gsnedders 11y agoTagSoup is pretty poor — it's far from being an HTML parser (as defined by the HTML spec). The big problem is that because it's really just a tokenizer, it doesn't do any of the handling of mis-matched tags, which is really the interesting part of parsing HTML. Even insofar as what HTML can be parsed by a streaming parser, it's not great, as it doesn't imply any tags (which are a big part of HTML!). It does, in its own code, state: -- We make some generalisations: -- <!name is a valid tag start closed by > -- <?name is a valid tag start closed by ?> -- </!name> is a valid closing tag -- </?name> is a valid closing tag -- <a "foo"> is a valid tag attibute in ! and ?, i.e missing an attribute name -- We also don't do lowercase conversion -- Entities are handled without a list of known entity names -- We don't have RCData, CData or Escape modes (only effects dat and tagOpen) All of which mean that it doesn't actually follow what the HTML spec says! Just because it claims to support the spec doesn't mean much!
- PaulAJ 11y agoI haven't used tagsoup, but I believe that is the point; it was designed to let you scrape data from badly formed HTML you got from somewhere else, rather than helpfully pointing out the broken tags.
- gsnedders 11y agoThe HTML spec defines how to parse any arbitrary stream of characters, and it is what is implemented in browsers and hence is what best supports badly-formed HTML (because it's typically written aimed at browsers!). Therefore, by not following the spec, TagSoup has worse compatibility with badly-formed HTML.