Skip to content

Instantly share code, notes, and snippets.

@abhillman
Created April 29, 2015 05:59
Show Gist options
  • Save abhillman/305d3c9a3a337b7708a1 to your computer and use it in GitHub Desktop.
Save abhillman/305d3c9a3a337b7708a1 to your computer and use it in GitHub Desktop.
import Network.HTTP.Conduit (simpleHttp)
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Char8 as C
import Text.XML.HXT.Core
import Data.List
urbanDictionaryURL :: String
urbanDictionaryURL = "https://www.urbandictionary.com/random.php"
getRandomUrbanEntry :: IO String
getRandomUrbanEntry = do
html <- simpleHttp urbanDictionaryURL >>= return . C.unpack
(runX $ (readString [withParseHTML yes, withWarnings no] html) //> hasAttrValue "class" (isInfixOf "example") >>> getChildren >>> getText) >>= (return . head)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment