【问题标题】:HtmlAgilityPack SelectNode doesn't works on WP8.1HtmlAgilityPack SelectNode 不适用于 WP8.1
【发布时间】:2015-09-16 14:02:39
【问题描述】:

在我的控制台项目上,它工作得很好......但是当我在 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]");

【问题讨论】:

  • 这是问答网站,这里的问题是什么?并确保在这里被问到的是on topic
  • 正如我所说,我试图在 WP8.1 上制作 .SelectsNodes(),但如果 XPath 在 WP8.1 上不支持,我怎么能做到这一点

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


【解决方案1】:

“我试图在 WP8.1 上制作 .SelectsNodes(),但如果 XPath 在 WP8.1 上不支持,我怎么能做到这一点”

当 HtmlAgilityPack (HAP) XPath API 不可用时,常见的替代方案是 LINQ API,例如:

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);

【讨论】:

  • 我在屏幕上遇到问题link
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 2015-03-10
  • 1970-01-01
  • 2014-12-25
相关资源
最近更新 更多