适用于 Windows 10 (UWP) 的 HTML 解析器 [英] HTML Parser for Windows 10 (UWP)
本文介绍了适用于 Windows 10 (UWP) 的 HTML 解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有将 X-Path
用于 UWP
- Windows 10 的 HTML 解析器?
Is there any HTML parser using X-Path
for UWP
- Windows 10?
在 Windows 10 中探索 HTML 的最简单/最好的方法是什么?
What's the easy/best way of exploring HTML in Windows 10 ?
推荐答案
解决方案 1:Install-Package HtmlAgilityPack
Solution 1: Install-Package 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 在 C# 中使用 C# 示例解析 HtmlVisual Studio 2013[^]
这篇关于适用于 Windows 10 (UWP) 的 HTML 解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文