Created
September 7, 2013 16:51
-
-
Save qoelet/6477179 to your computer and use it in GitHub Desktop.
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
import Network.Curl | |
import Text.XML.HXT.Core | |
import Control.Monad | |
import Data.List (isPrefixOf) | |
getHtmlRespOnly :: (CurlCode, String) -> String | |
getHtmlRespOnly (_, s) = s | |
main :: IO () | |
main = do | |
getHN <- curlGetString "https://news.ycombinator.com" [] | |
let contents = getHN | |
html = getHtmlRespOnly contents | |
doc = readString [withParseHTML yes, withWarnings no] html | |
isExternalLink = isPrefixOf "http://" | |
isYCombinator = isPrefixOf "http://ycombinator" | |
links <- runX $ doc //> hasName "a" >>> getAttrValue "href" | |
let links' = ([l | l <- links, (isExternalLink l) == True]) | |
mapM_ putStrLn ([l | l <- links', (isYCombinator l) == False]) | |
-- test output | |
{-| | |
(northpole)kenny@hbox:~/locker/haskell$ runhaskell web.hs | |
http://www.s3for.me/index.html | |
http://www.nytimes.com/2013/09/06/health/gut-bacteria-from-thin-humans-can-slim-mice-down.html?src=me&ref=general&_r=0 | |
http://vombat.tumblr.com/post/60530544401/date-parsing-performance-on-ios-nsdateformatter-vs | |
http://www.joystiq.com/2013/09/06/ouya-free-the-games-fund-project-suspended-by-kickstarter/ | |
http://www.linuxjournal.com/content/linux-vs-bullshit | |
http://www.sciencebasedmedicine.org/i-refute-it-thus/ | |
http://www.popehat.com/2013/09/06/nsa-codebreaking-i-am-the-other/ | |
http://productforums.google.com/forum/#!topic/maps/toaewYdz0kg | |
http://blog.agilebits.com/2013/09/06/1password-and-the-crypto-wars/ | |
http://www.fastcolabs.com/3016958/hey-japan-whats-up-with-your-startup-culture | |
http://www.usatoday.com/story/tech/2013/09/07/nasa-robotic-explorer-moon-va/2779137/ | |
http://www.indiegogo.com/projects/support-0-a-d-an-open-source-strategy-game/ | |
http://www.washingtonpost.com/business/technology/google-encrypts-data-amid-backlash-against-nsa-spying/2013/09/06/9acc3c20-1722-11e3-a2ec-b47e45e6f8ef_story.html?hpid=z1 | |
http://www.washingtonpost.com/blogs/the-switch/wp/2013/09/06/the-feds-pays-for-60-percent-of-tors-development-can-users-trust-it/ | |
http://learn.adafruit.com/introducing-trinket/introduction | |
http://www.wired.com/threatlevel/2013/09/tech-industry-tainted/ | |
http://www.wired.com/wiredenterprise/2013/09/nginx/ | |
http://blog.ircmaxell.com/2013/09/rambling-on-internals.html#comment-form | |
http://www.autocar.co.uk/car-video/video-tesla-model-s-vs-aston-martin-rapide-s | |
http://www.BeeLineReader.com | |
http://crystal-lang.org/2013/09/04/happy-birthday-crystal.html | |
|-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment