开发者

Selecting nodes that have an attribute with spaces using HTMLAgilityPack

开发者 https://www.devze.com 2023-03-08 02:56 出处:网络
I\'m trying to select all the li elements in from the following: <div> <ul> <li 开发者_运维问答class=\"third left\">

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.


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 ;)

0

精彩评论

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