Warm tip: This article is reproduced from serverfault.com, please click

F# count all present links on html website

发布于 2020-11-28 01:30:36

I am currently trying to create a simple F# function that can given a URL to a html site, count all the links present.

I know that it can be done somehow through counting the number of <a substrings, but not sure on how to actually search through the site and so on.

Any help is greatly appreciated.

Questioner
Emilio
Viewed
0
Avestura 2020-11-29 16:04:53

You can use HtmlParser from FSharp.Data package.

open FSharp.Data

let doc = HtmlDocument.Load "https://en.wikipedia.org/wiki/F_Sharp_(programming_language)"

let linksCount = doc.Descendants ["a"] |> Seq.length