In the python standard libraryXML. etree. elementtreeIt is easy to use and encapsulated for XML operations. However, there are some details that need to be noticed by users:
WhereXML. etree. elementtreeThe find and findall methods do not fully support XPath. Needless to say, xpath2.0 means that even xpath1.0 only supports a small part of xpath1.0. It can be said that it only supports a subset of xpath1.0.
The following example shows the problem:
Etree. Find ("Auto/process_thread_operate/Time ")
Etree. Find ("Auto/process_thread_operate/time [@ action = 'dns _ query']")
The running result is the same as expected, but if you run the following operations:
Etree. Find ("Auto/process_thread_operate/time [@ action = 'dns _ query' and @ action = 'HTTP _ access']")
An invalid predicate error is returned.
The reason is thatXML. etree. elementtree has limited support for xpath.
If you want to fully use XPath, we recommend that you use the lxml xpath