I am trying to get the basic example from http://egonschiele.github.io/HandsomeSoup/ to work:
main = do
doc <- fromUrl "http://www.google.com/search?q=egon+schiele"
links <- runX $ doc >>> css "h3.r a" ! "href"
mapM_ putStrLn links
I have tried to reproduce the example like so:
module Main (main) where
import Text.HandsomeSoup
import Text.XML.HXT.Core
import Control.Monad
main = do
doc <- fromUrl "http://www.google.com/search?q=egon+schiele"
links <- runX $ doc >>> css "h3.r a" ! "href"
mapM_ putStrLn links
But, I am getting the following error:
$ runhaskell Main.hs
Main.hs:8:21:
Couldn't match expected type `IOSLA (XIOState ()) XmlTree b0'
with actual type `hxt-9.3.0.1:Data.Tree.NTree.TypeDefs.NTree
hxt-9.3.0.1:Text.XML.HXT.DOM.TypeDefs.XNode'
In the first argument of `(>>>)', namely `doc'
In the second argument of `($)', namely
`doc >>> css "h3.r a" ! "href"'
In a stmt of a 'do' block:
links <- runX $ doc >>> css "h3.r a" ! "href"
But I really can't seem to figure out what's going on.
Function fromUrl has type fromUrl :: String -> IOSArrow XmlTree (NTree XNode). So IOSArrow XmlTree (NTree XNode) is not clear IO-action.
Simplest way fix it - use let statement instead:
import Text.HandsomeSoup
import Text.XML.HXT.Core
main :: IO ()
main = do
let doc = fromUrl "http://www.google.com/search?q=egon+schiele"
links <- runX $ doc >>> css "h3.r a" ! "href"
mapM_ putStrLn links