开发者

Html Agility Pack C#: Expression must evaluate to a node-set

I'm using Html Agility Pack to fetch a webpage. I want to collect all the TEXT I AM LOOKING FOR of the following form:

<li><a href="/deal/map/4087664" class="show-location" title="bla bla" data-address="TEXT I AM LOOKING FOR"></a></li>

I tried this code:

var web = new HtmlWeb();
var doc = web.Load(url);

var nodes1 = doc.DocumentNode.SelectNodes("//[@data-address]");
var nodes2 = doc.DocumentNode.SelectNodes("//[@data-address={0}]");

both threw an exception: Expression must evaluate to a node-set. How can i 开发者_Go百科correct my selector ?


I'm not an XPath expert by any means, but I suspect you want:

// Note the *
var nodes1 = doc.DocumentNode.SelectNodes("//*[@data-address]");

In other words "any element with a data-address attribute"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜