HTML解析器为Windows 10 (UWP)
本文关键字:UWP Windows HTML | 更新日期: 2023-09-27 18:03:06
是否有任何HTML解析器使用X-Path
UWP
- Windows 10?
在Windows 10中探索HTML最简单/最好的方法是什么?
解决方案一:Install-Package htmllagilitypack
https://www.nuget.org/packages/HtmlAgilityPack/解决方案2:解析Htmlprivate 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# for Visual Studio 2013中使用c#解析Html示例[^]