Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (20 sloc) 652 Bytes
module Links where
import Data.Maybe
import Network.URI
import Text.HTML.TagSoup
links :: String -> String -> [String]
links url = catMaybes .
map (canonicalizeLink url) .
filter (not . null) .
map (fromAttrib "href") .
filter (\t -> fromAttrib "rel" t /= "nofollow") .
filter (isTagOpenName "a") .
canonicalizeTags .
parseTags
canonicalizeLink :: String -> String -> Maybe String
canonicalizeLink referer path = do
r <- parseURI referer
p <- parseURIReference path
n <- p `nonStrictRelativeTo` r
let u = uriToString id n ""
return (takeWhile (/= '#') u)
Something went wrong with that request. Please try again.