【发布时间】:2012-02-10 22:00:36
【问题描述】:
我正在尝试做一些简单的事情,但不知何故它对我不起作用,这是我的代码:
var items = html.DocumentNode.SelectNodes("//div[@class='itembox']");
foreach(HtmlNode e in items)
{
int x = items.count; // equals 10
HtmlNode node = e;
var test = e.SelectNodes("//a[@class='head']");// I need this to return the
// anchor of the current itembox
// but instead it returns the
// anchor of each itembox element
int y =test.count; //also equals 10!! suppose to be only 1
}
我的 html 页面如下所示:
....
<div class="itembox">
<a Class="head" href="one.com">One</a>
</div>
<div class="itembox">
<a Class="head" href="two.com">Two</a>
</div>
<!-- 10 itembox elements-->
....
我的 XPath 表达式有误吗?我错过了什么吗?
【问题讨论】:
标签: c# .net html xpath html-agility-pack