Skip to content
Advertisement

selecting attribute values from lxml

I want to use an xpath expression to get the value of an attribute.

I expected the following to work

JavaScript

but this gives an error :

JavaScript

Am I wrong to expect this to work?

Advertisement

Answer

find and findall only implement a subset of XPath. Their presence is meant to provide compatibility with other ElementTree implementations (like ElementTree and cElementTree).

The xpath method, in contrast, provides full access to XPath 1.0:

JavaScript

However, you could instead use get:

JavaScript

or attrib:

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