使用HTMLAgilityPack选择具有空格属性的节点 [英] Selecting nodes that have an attribute with spaces using HTMLAgilityPack
问题描述
我正在尝试从以下选项中选择所有li
元素:
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>
我正在使用以下XPath查询,但这不会返回任何内容.
I'm using the following XPath query but this returns nothing.
Dim result As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//li[@class='third left']")
对空格的属性是否有不同的对待?使用此工具,XPath可以正常工作.
Are attributes with spaces treated differently? Using this tool the XPath works correctly.
推荐答案
正如@SimonMourier所说,您的XPath是正确的.我建议您执行以下操作:
As @SimonMourier said, your XPath is correct. I suggest you doing the following:
-
发布整个HTML源,并告诉我们是从文件中加载还是直接从Web加载
Posting the entire HTML source and telling us if you're loading it from a file or directly from the web
将htmlDoc.DocumentNode.OuterHtml
的内容写入文本文件.如果您是从网络上加载HTML,则可能是 404 (找不到 )之类的东西;)
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 ;)
这篇关于使用HTMLAgilityPack选择具有空格属性的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!