I have a complex html DOM tree of the following nature:
<table>
...
<tr>
<td>
...
</td>
<td>
<table>
<tr>
<td>
<!-- inner most table -->
<table>
...
</table>
<h2>This is hell!</h2>
<td>
</tr>
</table>
</td>
</tr>
</table>
I have some logic to find out the inner most table. But after having found it, I need to get the next sibling element (h2). Is there anyway you can do this?
If
tagis the innermost table, thenwill be
To literally get the next sibling, you could use
tag.nextSibling,which in this case, is
u'\n'.If you want the next sibling that is not a NavigableString (such as
u'\n'), then you could useIf you want the second sibling (no matter what it is), you could use
(but note that if
tagdoes not have a next sibling, thentag.nextSiblingwill beNone, andtag.nextSibling.nextSiblingwill raise anAttributeError.)