HTML Parser for Windows 10 (UWP)

我们两清 提交于 2019-12-12 12:46:57

问题


Is there any HTML parser using X-Path for UWP - Windows 10?

What's the easy/best way of exploring HTML in Windows 10 ?


回答1:


Solution 1: Install-Package HtmlAgilityPack

https://www.nuget.org/packages/HtmlAgilityPack/

Solution 2: Parsing Html

private async void Parsing(string website)
       {
           try
           {
               HttpClient http = new HttpClient();
               var response = await http.GetByteArrayAsync(website);
               String source = Encoding.GetEncoding("utf-8").GetString(response, 0, response.Length - 1);
               source = WebUtility.HtmlDecode(source);
               HtmlDocument resultat = new HtmlDocument();
               resultat.LoadHtml(source);


           List<HtmlNode> toftitle = resultat.DocumentNode.Descendants().Where
           (x => (x.Name == "div" && x.Attributes["class"] != null && x.Attributes["class"].Value.Contains("block_content"))).ToList();

           var li = toftitle[6].Descendants("li").ToList();
           foreach (var item in li)
           {
               var link = item.Descendants("a").ToList()[0].GetAttributeValue("href", null);
               var img = item.Descendants("img").ToList()[0].GetAttributeValue("src", null);
               var title = item.Descendants("h5").ToList()[0].InnerText;

               listproduct.Add(new Product()
               {
                   Img = img,
                   Title = title,
                   Link = link
               });
           }

       }
       catch (Exception)
       {

           MessageBox.Show("Network Problem!");
       }

   }

Windows 8 Parsing Html using C# sample in C# for Visual Studio 2013[^]



来源:https://stackoverflow.com/questions/31454429/html-parser-for-windows-10-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!