Skip to content

Instantly share code, notes, and snippets.

@ishiy1993
Created October 13, 2015 05:26
Show Gist options
  • Save ishiy1993/afc7bf2cdcc3d0c78380 to your computer and use it in GitHub Desktop.
Save ishiy1993/afc7bf2cdcc3d0c78380 to your computer and use it in GitHub Desktop.
Haskellで簡単Webクライアント
{-# LANGUAGE OverloadedStrings #-}
import Text.XML.Cursor
import Text.HTML.DOM (parseLBS)
import Network.HTTP.Conduit
import qualified Data.Text as T
import qualified Data.Text.IO as T
main :: IO ()
main = do
doc <- parseLBS <$> simpleHttp "http://www.ishiy.xyz/archive.html"
let root = fromDocument doc
let entries = pickUpEntry root
putStrLn $ ("総記事数: " ++) . show $ length entries
putStrLn "記事一覧:"
T.putStr $ T.unlines $ map ("- " `T.append`) entries
pickUpEntry :: Cursor -> [T.Text]
pickUpEntry r = r $// element "div"
>=> attributeIs "class" "entry"
>=> child
>=> element "ul"
>=> child
>=> element "li"
>=> child
>=> element "a"
&// content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment