Python-- finds elements through xpath relative node position (continued)
I have previously written methods relative to the parent element and the next sibling element.
This time supplement all the methods that xpath uses to find elements relative to the position of the node. Instead of citing examples, you can go to practice.
Xpath relative node search method:
1. Xpath ('. / ancestor::*')
Find all ancestor nodes of the current node, that is, parent or grandfather nodes
2. Xpath (. / ancestor-or-self::*')
Find all ancestor nodes of the current node as well as itself
3. Xpath (. / attribute::*')
Get all the attributes of the current node
4. Xpath ('. / child::*')
Find all children of the current node
5. Xpath ('. / descendant::*')
Get all descendant nodes of the current node, that is, child node and grandnode
6. Xpath ('. / following::*')
Gets all nodes after the end tag of the current node
7. Xpath ('. / following-sibing::*')
Gets the next sibling node of the current node
8. Xpath ('. / parent::*')
Gets the parent node of the current node
9. Xpath (. / preceding::*')
Gets all nodes before the start label of the current node
10. Xpath ('. / preceding-sibing::*')
Gets the last sibling node of the current node
11. Xpath ('. / self::*')
Select the current node
That's about it, and these methods are very useful, especially if some elements cannot be found through their own attributes, they need to be found relative to the location of the node.