Reputation: 41
<table class="attributes">
<tbody>
<tr>
<td class="label title"><b>scale</b></td>
<td class="value">1/48</td>
<td class="label title"><b>products</b></td>
<td class="value">Plastic kits</td>
</tr>
<tbody>
</table>
Hit a brain block on this one...
Trying to capture specific values within the td's. So the first time around I'll grab the first, then the second and so on...
//table[@class='attributes']/tbody/tr//descendant::td[@class='value']
Gives me all the td values how to select only the 2nd or 3rd.
I've tried:
"//table[@class='attributes']/tbody/tr//descendant::td[@class='value']/td[2]"
With no success.
For example:
$x("//*[@class='attributes']/tbody/tr/td[@class='value']")
finds me
[<td class="value">1/48</td>, <td class="value">Plastic kits</td>, <td class="value">Limited edition</td>, <td class="value">Aircraft</td>, <td class="value">Eduard</td>, <td class="value">0.5 kg</td>]
So then I changed the XPath to:
$x("//*[@class='attributes']/tbody/tr/td[@class='value'][1]")
adding the [1] and what it does is returns
[<td class="value">1/48</td>, <td class="value">Limited edition</td>, <td class="value">Eduard</td>]
Upvotes: 2
Views: 15079
Reputation: 111726
To select all of the class='value'
td
elements beneath the class='attributes'
table
:
/table[@class='attributes']//td[@class='value']
selects:
<td class="value">1/48</td>
<td class="value">Plastic kits</td>
To select just the second such td
:
(/table[@class='attributes']//td[@class='value'])[2]
Upvotes: 4