HtmlAgilityPack SelectNode不适用于WP8.1

时间:2015-06-29 23:05:27

标签: c# linq windows-phone-8.1 html-parsing html-agility-pack

在我的控制台项目中,它的效果很好......但是当我在Windows Phone 8.1上制作它时,它不起作用。问题是什么?

HtmlNodeCollection NoAltElements = HD.DocumentNode.SelectNodes("//div[@class='f2p-card']//div[@class='champion-info']//a[@href]");


HtmlNodeCollection NoAltElements = HD.DocumentNode.SelectNodes("//div[@class='white-stone']//a[@href]");

1 个答案:

答案 0 :(得分:1)

"im trying to make .SelectsNodes() on WP8.1, but cant understand how can i do this if XPath doesnt support on WP8.1"

Common alternative when HtmlAgilityPack (HAP) XPath API not available is LINQ API, for example :

IEnumerable<HtmlNode> NoAltElements =
                        HD.DocumentNode
                          .Descendants("div")
                          .Where(o => o.GetAttributeValue("class", "") == "f2p-card")
                          .SelectMany(o => o.Descendants("div"))
                          .Where(o => o.GetAttributeValue("class", "") == "champion-info")
                          .SelectMany(o => o.Descendants("a"))
                          .Where(o => o.GetAttributeValue("href", null) != null);

IEnumerable<HtmlNode> NoAltElements = 
                        HD.DocumentNode
                          .Descendants("div")
                          .Where(o => o .GetAttributeValue("class","") == "white-stone")
                          .SelectMany(o => o.Descendants("a"))
                          .Where(o => o .GetAttributeValue("href",null) != null);