问题
I'm trying to select all the li
elements in from the following:
<div>
<ul>
<li class="third left">
...
</li>
<li class="third left">
...
</li>
</ul>
</div>
I'm using the following XPath query but this returns nothing.
Dim result As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//li[@class='third left']")
Are attributes with spaces treated differently? Using this tool the XPath works correctly.
回答1:
As @SimonMourier said, your XPath is correct. I suggest you doing the following:
Posting the entire HTML source and telling us if you're loading it from a file or directly from the web
Writing in a text file the content of
htmlDoc.DocumentNode.OuterHtml
into a text file. If you're loading the HTML from the web, maybe you're getting a 404 (Not Found) or something ;)
来源:https://stackoverflow.com/questions/6105216/selecting-nodes-that-have-an-attribute-with-spaces-using-htmlagilitypack