7

i used to select table with class name "list". I use this xpath query to select node in Htmlagilitypack

//table[@class="list"]/td/a[@href]

but couldn't get correct output. What's wrong with my xpath code block?

This is the table that i want to grab the data from:

<table class="list">
<tbody>
    <tr>
        <td width="315">
            <b>1</b> <a href="http://www.url.html">data</a><br>
            <b>2</b> <a href="http://www.url.html">data</a><br>
            <b>3</b> <a href="http://www.url.html">data</a><br>
        </td>
    </tr>
</tbody>
</table>
1
  • You missed tbody and tr: //table[@class="list"]/tbody/tr/td/a[@href] or //table[@class="list"]//td/a[@href]
    – VikciaR
    May 13, 2011 at 5:40

1 Answer 1

9

I consider that you need to get href values of all the anchors. For that you could use //table[@class='list']//td/a/@href

Your XPath did not work because you are trying to find such a <TD> which is immediate child of <TABLE> which is not the case in the code snippet you've shown. Hence use //TD in your XPath.

Hope this helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.