Skip to content
Advertisement

I am not able to resolve ‘lxml.etree.XPathEvalError: Invalid expression’ error on a legal XPATH expression

I am trying to parse an xpath but it is giving Invalid expression error.

The code that should work:

JavaScript

Expected result is a boolean value but it is showing error:

JavaScript

Advertisement

Answer

The exception is because name() isn’t a valid node type. Your XPath would only be valid as XPath 2.0 or greater. lxml only supports XPath 1.0.

You would need to move the name() != 'warning' into a predicate.

Also, if you want a True/False result, wrap the xpath in boolean()

JavaScript

Full example…

JavaScript

This would print False.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement