【发布时间】:2011-10-13 21:57:18
【问题描述】:
这就是我要解析的内容
<div class="photoBox pB-ms">
<a href="/user_details?userid=ePDZ9HuMGWR7vs3kLfj3Gg">
<img width="100" height="100" alt="Photo of Debbie K." src="http://s3-media2.px.yelpcdn.com/photo/xZab5rpdueTCJJuUiBlauA/ms.jpg">
</a>
</div>
我正在使用以下 XPath 来查找它
HtmlNodeCollection bodyNode = htmlDoc.DocumentNode.SelectNodes("//div[@class='photoBox pB-ms']");
这很好,返回,s me all div,s with photobox class
但是当我想使用 ahref 时
HtmlNodeCollection bodyNode = htmlDoc.DocumentNode.SelectNodes("//div[@class='photoBox pB-ms'//a href]");
我收到错误无效令牌。
我也尝试过使用查询
var lowestreview =
from main in htmlDoc.DocumentNode.SelectNodes("//div[@class='photoBox pB-ms']")
from rating in main.SelectNodes("//a href")
select new { Main=main.Attributes[0].Value,AHref = rating.ToString() };
谁能告诉我如何编写 XPath 或查询来获得这个 AHref
【问题讨论】:
标签: c# html-parsing html-agility-pack