Created
October 13, 2015 05:26
-
-
Save ishiy1993/afc7bf2cdcc3d0c78380 to your computer and use it in GitHub Desktop.
Haskellで簡単Webクライアント
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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