Thank you, and to Jens too.

The newbie in me (wrongly) assumed that xpath() returned a pointer to the element if only one was found in the HTML file, like find().

On 30/05/2022 09:30, holger.jo...@lbbw.de wrote:
Through trial and error, it looks like xpath() returns an array, even if only 
one
element is found in the tree.
Behold the power of the great docs: https://lxml.de/xpathxslt.html#xpath

"[...]
XPath return values

The return value types of XPath evaluations vary, depending on the XPath 
expression used:

     - True or False, when the XPath expression has a boolean result
     - a float, when the XPath expression has a numeric result (integer or 
float)
     - a 'smart' string (as described below), when the XPath expression has a 
string result.
     - a list of items, when the XPath expression has a list as result. The 
items may include Elements (also comments and processing instructions),
         strings and tuples. Text nodes and attributes in the result are 
returned as 'smart' string values. Namespace declarations are returned as tuples
         of strings: (prefix, URI).
[...]"

;-)
_______________________________________________
lxml - The Python XML Toolkit mailing list -- lxml@python.org
To unsubscribe send an email to lxml-le...@python.org
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: arch...@mail-archive.com

Reply via email to