1. What is xpath
1. XPath (XML Path Language) is a language for finding information in HTML\XML documents, and can be used to traverse elements and attributes in HTML\XML documents.
2. Know xml
The difference between html and xml
xml tree structure
Three. The usage of xpath
XPath uses path expressions to select nodes or sets of nodes in an XML document. These path expressions are very similar to the expressions we see in regular computer file systems.
1 Useful expressions
2. In the table below, we have listed some path expressions and the results of the expressions:
3. Pick unknown nodes
4 some cases
Four. Summary
- An overview of xpath XPath (XML Path Language), a language for parsing, searching, and extracting information
- Node relationship of xpath: root node, child node, peer node
- Key syntax of xpath to get any node: //
- Key syntax of xpath to get nodes based on attributes: tag[@attribute='value']
- Get the text of the node in xpath: text()
- Get node attribute value of xpath: @attribute name
5. Expand knowledge
1. Escape characters
raw string
1 Since the backslash in the string has a special effect, when the string contains a backslash, you need to use the escape character \ to escape each "" contained in the string.
For example, we want to write a string about the Windows path G:\publish\codes\02\2.4. If we write this directly in the Python program, it will definitely not work. We need to use the \ escape character for each character in the string. "" to escape, that is, to write in the form of G:\publish\codes\02\2.4.