网站解析c# - Html Agility Pack

时间:2014-07-21 07:46:31

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

我想解析网站的<a href=""></a>标记。我试图在每个这样的&#39;描述&#39;中获得href属性值。跨班。

enter image description here

我尝试了以下代码

HtmlNodeCollection sp = htmlDocument.DocumentNode.SelectNodes("//span[@class='description']//a");
                        foreach (HtmlNode link in sp)
                        {
                            HtmlAttribute att = link.Attributes["href"];
                            System.Diagnostics.Debug.WriteLine(att.Value);
                        }

我无法获取href属性值。我的错是什么?

1 个答案:

答案 0 :(得分:2)

enter image description here 您可以使用chrome开发人员工具(F12),它可以帮助您轻松获得正确的xPath语法(复制XPath)