Xpath detailed explanation
What is Xpath?
Xpath is a language used to locate elements in XML documents, and it also supports parsing of HTML elements.
The so-called Xpath means XML path language. Path is the path, so Xpath mainly looks for elements through the path.
Let's take a look at the structure in HTML through the following small picture:
The structure of HTML is a tree structure, HTML is the root node, and all other element nodes are emitted from the root node. The other elements are the Node nodes on the tree, and each node may also have attributes and text.
The path refers to the route from one node to another.
There are various relationships between nodes:
Parent node (Parent): HTML is the parent of body and head nodes; child nodes (Child): head and body are children of HTML; sibling nodes (Sibling): have the same parent node, head and body are sibling nodes. Title and div are not brothers because they are not the same parent node. Ancestor node (Ancestor): body is the ancestor node of form, grandparents and above