Created
October 15, 2012 09:48
-
-
Save takaki/3891747 to your computer and use it in GitHub Desktop.
HXT, XPath
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
import Codec.Binary.UTF8.String | |
import Codec.Text.IConv | |
import Data.List | |
import Text.XML.HXT.Core | |
import qualified Data.ByteString.Lazy as BSL | |
import Text.XML.HXT.XPath.Arrows | |
-- 日本語 | |
main = do | |
cs <- BSL.readFile "4731398C.html" | |
let u8s = convert "CP932" "UTF-8" cs | |
let html = decode (BSL.unpack u8s) | |
let doc = readString [withParseHTML yes, withWarnings no] html | |
nodes <- runX $ doc | |
>>> | |
getXPathTrees "//*[@id=\"main\"]/form/div[4]/table/tr/td[1]/table[1]/tr[1]/td/div/p" | |
//> getText | |
mapM_ ( putStrLn . id) nodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment