I have this code:
<table cellspacing="1" cellpadding="1" border="0">
<tbody>
<tr>
<td>Something else</td>
</tr>
<tr>
<td valign="top">
<a href="http://exact url">Something</a>
</td>
<td valign="top">Something else</td>
</tr>
</tbody>
</table>
I want to find the Table but is very hard to target it (the very same code is used like 10 times). But I know what is in the URL. How can I get then the parent table?
If t
is the etree
for this snippet of XML, then the link you're looking for is
t.xpath('//a[@href = "http://exact url"]')[0]
From there, you can get to the table
using the ancestor
axis:
t.xpath('//a[@href = "http://exact url"]/ancestor::table')[-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With