@hackage html-conduit1.3.0
Parse HTML documents using xml-conduit datatypes.
Categories
License
MIT
Maintainer
michael@snoyman.com
Links
Versions
Installation
Dependencies (10)
- base >=4 && <5
- bytestring
- conduit >=1.3
- containers
- resourcet >=1.2
- tagstream-conduit >=0.5.5.3 && <0.6 Show all…
Dependents (23)
@hackage/microformats2-parser, @hackage/html2hamlet, @hackage/fedora-img-dl, @hackage/dom-selector, @hackage/cattrap, @hackage/http-directory, Show all…
This package uses tagstream-conduit for its parser. It automatically balances mismatched tags, so that there shouldn't be any parse failures. It does not handle a full HTML document rendering, such as adding missing html and head tags.
Simple usage example:
#!/usr/bin/env stack
{- stack --install-ghc --resolver lts-6.23 runghc
--package http-conduit --package html-conduit
-}
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as T
import Network.HTTP.Simple (httpSink)
import Text.HTML.DOM (sinkDoc)
import Text.XML.Cursor (attributeIs, content, element,
fromDocument, ($//), (&/), (&//))
main :: IO ()
main = do
doc <- httpSink "http://www.yesodweb.com/book" $ const sinkDoc
let cursor = fromDocument doc
T.putStrLn "Chapters in the Yesod book:\n"
mapM_ T.putStrLn
$ cursor
$// attributeIs "class" "main-listing"
&// element "li"
&/ element "a"
&/ content