Created
May 3, 2020 13:04
-
-
Save bombless/53d42464400b8ac69e3a0b95907795cd to your computer and use it in GitHub Desktop.
Haskell fetch GBK web page
This file contains hidden or 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
#!/usr/bin/env stack | |
-- stack script --resolver lts-12.21 | |
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Network.HTTP.Simple as Http | |
import qualified Codec.Text.IConv as IConv | |
import qualified Data.ByteString.Lazy as BSL | |
import qualified Data.ByteString.Lazy.Char8 as BSLC | |
-- check | |
main :: IO () | |
main = do | |
response <- Http.httpBS "https://search.51job.com/list/030200,000000,0000,00,9,99,haskell,2,1.html" | |
putStrLn $ "The status code was: " ++ | |
show (Http.getResponseStatusCode response) | |
print $ Http.getResponseHeader "Content-Type" response | |
let body = Http.getResponseBody response | |
let utf8Body = IConv.convert "GB18030" "UTF-8" $ BSL.fromStrict body | |
BSLC.putStrLn utf8Body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment