-5

I have the following code:

<div id="list">
  <table>
    <tr>
      <th>STT</th>
      <th>Link</th>
    </tr>

    <tr>
      <td>Line 1</td>
      <td><a href="http://website.com/link1">Link 1</a></td>
    </tr>

    <tr>
      <td>Line 2</td>
      <td><a href="http://website.com/link2">Link 2</a></td>
    </tr>
  </table>
</div>

How can I get:

http://website.com/link1

http://website.com/link2

Termininja
  • 6,620
  • 12
  • 48
  • 49

1 Answers1

1

The Xpath to get the hrefs of a elements in the table in the exact structure you've given:

htmlDoc.DocumentNode.SelectNodes("//div[@id='list']/table/tr[td]/td[a]/a");

And then scrape out all of the @href Attributes.

Unpacked:

Find the div with attribute id with value of 'list', then navigate into child table , then just those tr rows with a td child, then, similarly, to the td elements with an a child.

StuartLC
  • 104,537
  • 17
  • 209
  • 285