Home
Insert
Update snippet 'Searches the web and counts the words of results descriptions'
Title
Description
This F# scripts uses PickAll (github.com/gsscoder/pickall) to search the web with Google, DuckDuckGo and Yahoo. Results descriptions are than split to words and counted.
Source code
(* * pickall_words.fsx * F# Script that demonstrates use of PickAll (github.com/gsscoder/pickall) * Searches the web and counts the words of results descriptions * Requires PickAll.dll and AngleSharp.dll in the script directory *) #r "PickAll.dll" open System open Microsoft.FSharp.Control open PickAll open PickAll.Searchers let alpha (s : string) = not (s.ToCharArray() |> Seq.map (fun x -> Char.IsLetterOrDigit(x) && not (Char.IsWhiteSpace(x))) |> Seq.contains false) let query = "Steve Jobs" let context = (new SearchContext()) .With<Google>() .With<DuckDuckGo>() .With<Yahoo>() let results = context.SearchAsync(query) |> Async.AwaitTask |> Async.RunSynchronously let words = results |> Seq.map (fun x -> x.Description.Split()) |> Seq.concat words |> Seq.filter alpha |> Seq.countBy id |> Seq.sortBy (fun (_, y) -> -y) |> Seq.iter (fun (x, y) -> printfn "%s %d" x y)
Tags
#strings
#web
#strings
#web
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update