I am parsing a webpage that includes a structure like this:
<tr>
<td>Label 1</td>
<td>Label 2</td>
<td>Label 3</td>
<td>Something else</td>
<\tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<\tr>
What I need to do is select an item based on it's label, so my thought is if the label is in the 3rd tag in it's row, I can grab the 3rd tag in the next row to find the item. I can't figure out a way to use the position() function in this way, and maybe xpath (1.0) is unable to handle this type of filtering.
My best attempt so far is: //td[ancestor::tr[1]/preceding-sibling::tr[1]/td[position()]]
. I was hoping the position() function would grab the position of the <td>
at the beginning of the xpath, since the rest of the xpath is a filter for that node.
Is what I'm trying to do even possible?