Some alternatives to @Arup answer:
tree.xpath("//p[b='Header 2']/following-sibling::table[1]")
select the first table sibling next to p containing heading b containing "Heading 2"
tree.xpath("//b[.='Header 2']/following::table[1]")
select the first table in the order of the document after b containing "Title 2"
For more information on the different axes, see the XPath 1.0 specification :
the next axis contains all nodes in the same document as the node context, which after the node context are in document order, excluding any descendants and excluding node nodes and namespace nodes
the next sibling axis contains all of the following siblings of the node context; if the node context is a node attribute or node namespace, the next sibling axis is empty
paul trmbrth
source share