diff options
author | Joris Guyonvarch | 2015-04-11 11:50:48 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-04-11 12:03:22 +0200 |
commit | 5977e1454d7738ddb086d37b20337e350e380790 (patch) | |
tree | e03261144e3d534434242c1dd037c2a4e4db5a9f /src/Page.hs |
Fetch first page ads of a given leboncoin url, fetch also the description page of each item.
Diffstat (limited to 'src/Page.hs')
-rw-r--r-- | src/Page.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Page.hs b/src/Page.hs new file mode 100644 index 0000000..b70db70 --- /dev/null +++ b/src/Page.hs @@ -0,0 +1,15 @@ +module Page + ( getPage + ) where + +import Control.Exception (SomeException, try) + +import Network.HTTP (simpleHTTP, getRequest, getResponseBody) + +getPage :: String -> IO (Either String String) +getPage url = + mapLeft show <$> (try (simpleHTTP (getRequest url) >>= getResponseBody) :: IO (Either SomeException String)) + +mapLeft :: (a -> c) -> Either a b -> Either c b +mapLeft f (Left l) = Left (f l) +mapLeft _ (Right r) = (Right r) |