How to use the HtmlDocument in .Net Core and UWP.
Solution: HtmlAgilityPack
To do this, you can install the NuGet Package HtmlAgilityPack from ZZZ Projects.
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams). |
If you have installed the HtmlAgilityPack, then you only have to insert a link into the MainPage
//< using > using HtmlAgilityPack; //HtmlDocument using System.Net; //*WebRequest using System.Threading.Tasks; //*Task //</ using > |
Then you can embed the code in the UWP application
Complete code Example of reading a webpage in an HTMLDocument
private async Task<HtmlDocument> Web_Get_HtmlDocument(string sURL) { //------------< fx_read_Page() >------------ //* get the HTML Document of a website-URL try { //-< init >- //< WebRequest and Response > WebRequest objRequest = WebRequest.Create(sURL); WebResponse objResponse = await objRequest.GetResponseAsync(); //</ WebRequest and Response >
//< Stream and Reader > Stream objDataStream = objResponse.GetResponseStream(); StreamReader TextReader = new StreamReader(objDataStream); //</ Stream and Reader > //-</ init >-
//< download > //* Read Website to local String string sHTML = TextReader.ReadToEnd(); //</ download >
//< get HTMLdocument > //*create and load to local HtmlDocument HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(sHTML); //</ get HTMLdocument >
//< output > return doc; //</ output > } catch (Exception) { return null; }
//------------</ fx_read_Page() >------------ }
|