Skip to content

Instantly share code, notes, and snippets.

@bombless
Created May 3, 2020 13:04
Show Gist options
  • Save bombless/53d42464400b8ac69e3a0b95907795cd to your computer and use it in GitHub Desktop.
Save bombless/53d42464400b8ac69e3a0b95907795cd to your computer and use it in GitHub Desktop.
Haskell fetch GBK web page
#!/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