Work with HTML more easily in HXT
|LTS Haskell 20.16:||0.4.2|
|Stackage Nightly 2023-03-30:||0.4.2|
|Latest on Hackage:||0.4.2|
Maintained by email@example.com
This version can be pinned in stack with:
Module documentation for 0.4.2
Depends on 11 packages(full list with versions):
base, containers, HandsomeSoup, HTTP, hxt, hxt-http, mtl, network, network-uri, parsec, transformers
Used by 1 package in nightly-2023-02-08(full list with versions):
Current Status: Usable and stable. Needs GHC 7.6. Please file bugs!
HandsomeSoup is the library I wish I had when I started parsing HTML in Haskell.
It is built on top of HXT and adds a few functions that make it easier to work with HTML.
Most importantly, it adds CSS selectors to HXT. The goal of HandsomeSoup is to be a complete CSS2 selector parser for HXT.
cabal install HandsomeSoup
Nokogiri, the HTML parser for Ruby, has an example showing how to scrape Google search results. This is easy in HandsomeSoup:
import Text.XML.HXT.Core import Text.HandsomeSoup main = do let doc = fromUrl "http://www.google.com/search?q=egon+schiele" links <- runX $ doc >>> css "h3.r a" ! "href" mapM_ putStrLn links
What can HandsomeSoup do for you?
Easily parse an online page using
let doc = fromUrl "http://example.com"
Or a local page using
contents <- readFile [filename] let doc = parseHtml contents
Easily extract elements using
Here are some valid selectors:
doc <<< css "a" doc <<< css "*" doc <<< css "a#link1" doc <<< css "a.foo" doc <<< css "p > a" doc <<< css "p strong" doc <<< css "#container h1" doc <<< css "img[width]" doc <<< css "img[width=400]" doc <<< css "a[class~=bar]" doc <<< css "a:first-child"
Easily get attributes using
doc <<< css "img" ! "src" doc <<< css "a" ! "href"
Find Haddock docs on Hackage.
I also wrote The Complete Guide To Parsing HXT With Haskell.
Made by Adit.