Demos/ProSol.WebScrap/Program.cs

20 lines
529 B
C#
Raw Normal View History

2023-12-08 07:55:03 +01:00
using ProSol.WebScrap;
2023-11-06 17:29:11 +01:00
var request = "https://en.wikipedia.org/wiki/Food_energy";
// Download the html:
using var client = new HttpClient();
using var response = await client.GetAsync(request);
var html = await response.Content.ReadAsStringAsync();
// Run the WebScrapper:
var css = "#firstHeading";
2023-12-08 07:55:03 +01:00
var result = WebScrapper
.Run(html, css)
2023-11-06 17:29:11 +01:00
.ToJsonString();
// Get the results:
Console.WriteLine(result);
// OUTPUT:
// [{"key":"#firstHeading","values":[{"value":"Food energy"}]}]
Console.Read();