c# - 适用于 Windows 10 (UWP) 的 HTML 解析器

标签 c# windows-10 windows-10-mobile

对于 UWP - Windows 10,是否有任何使用 X-Path 的 HTML 解析器?

在 Windows 10 中探索 HTML 的简单/最佳方法是什么?

最佳答案

方案一:安装包HtmlAgilityPack

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

方案二:解析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[^]

关于c# - 适用于 Windows 10 (UWP) 的 HTML 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31454429/

相关文章:

windows - 从注册表中获取 Windows 版本的可靠方法

uwp - 获取通话记录仅返回最后 20 条日志

audio - UWP Windows 10 JS - 直接编译到我的设备时后台音频工作,但从商店打开时不工作

c# - WPF Datagrid 打印 - 分组分页

c# - 新的 Mercosul 牌照正则表达式

c# - Entity Framework : Help Creating Database using Code first Approach

mysql 5.7.18 无法在 Windows 10 上启动

c# - 如何使用 C# 将 SQL 表传递并格式化为 excel

python - Pycharm/Windows 10 键盘快捷键冲突

c# - 适用于 Windows 10 的 HLS 播放器