Selecting nodes that have an attribute with spaces using HTMLAgilityPack

前提是你 提交于 2019-12-13 04:09:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!