invalid predicate when using text() in query
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
Python : sys.version_
lxml.etree : (4, 6, 3, 0)
libxml used : (2, 9, 10)
libxml compiled : (2, 9, 10)
libxslt used : (1, 1, 34)
libxslt compiled : (1, 1, 34)
I have this html tree
```
>>> tree = etree.fromstrin
<html><body>
<div>
<table>
<tr>
</tr>
</table>
<table>
<tr>
</tr>
</table>
</div>
</body></html>
""")
```
and I keep getting an error when trying to do the following query on the tree (I'm specifically trying to walk the table elements that have a specific header value)
```
>>> tree.find(
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
SyntaxError: invalid predicate
```
meanwhile this works as expected
```
>>> finder = etree.XPath(
>>> finder(tree)
[<Element table at 0x7fde6812f988>]
```
It looks like the `tree.find` query fails whenever I try to use the path names or the text() operator as part of the filter. I would've expected `tree.find` (and `iterfind`) to support the same syntax as `etree.XPath` so you can efficiently iterate the tree one at a time. Is this a bug or are more advanced queries just not supported?
> Is this a bug or are more advanced queries just not supported?
Missing features. find() and friends (a.k.a. ElementPath) only support a subset of XPath (and use an independent implementation), which could be extended. PRs welcome.
Note that ElementPath is mostly what CPython's xml.etree. ElementPath module provides in the standard library.