Here is the code:
This file contains 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
open System.IO | |
// from: http://htmlagilitypack.codeplex.com/ | |
#r @"C:\local\lib\HtmlAgilityPack\HtmlAgilityPack.dll" | |
open HtmlAgilityPack | |
let getLinks url = | |
let fetchdata (url:string) = | |
let req = System.Net.WebRequest.Create(url) | |
let resp = req.GetResponse() | |
let stream = resp.GetResponseStream() | |
let reader = new StreamReader(stream) | |
let data = reader.ReadToEnd() | |
resp.Close() | |
data | |
let doc = new HtmlDocument() | |
doc.LoadHtml (fetchdata url) | |
let links = doc.DocumentNode.SelectNodes "//a[@href]" | |
links | |
|> Seq.map (fun x -> x.GetAttributeValue ("href", "no url"), x) | |
|> Seq.filter (fun (x,y) -> x.StartsWith "http") | |
|> Seq.distinctBy (fun (x,y) -> x) | |
|> Seq.iter (fun (x,y) -> (printfn "%s [%s]" x y.InnerText)) |
No comments:
Post a Comment