【发布时间】:2016-02-24 21:42:47
【问题描述】:
我通过以下方式获得一个 IO 字符串:
import Data.Char
import Network.HTTP
import Text.HTML.TagSoup
openURL :: String -> IO String
openURL x = getResponseBody =<< simpleHTTP (getRequest x)
crawlType :: String -> IO String
crawlType pkm = do
src <- openURL url
return . fromBody $ parseTags src
where
fromBody = unwords . drop 6 . take 7 . words . innerText . dropWhile (~/= "<p>")
url = "http://pokemon.wikia.com/wiki/" ++ pkm
我想通过以下方式解析其数据:
getType :: String -> (String, String)
getType pkmType = (dropWhile (== '/') $ fst b, dropWhile (== '/') $ snd b)
where b = break (== '/') pkmType
但如你所见,getType 还不支持 IO 字符串。
我是 IO 新手,那么如何让它发挥作用? 在将 IO 字符串提供给该函数时,我也尝试理解错误,但到目前为止对我来说太复杂了:/
【问题讨论】: