使用HTMLAgilityPack选择具有空格属性的节点 [英] Selecting nodes that have an attribute with spaces using HTMLAgilityPack

查看:91
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆