May-27-2022, 01:05 PM
Hello,
I'm not very good at XPath, and am a bit lost at the syntax to 1) find an element based on the value of its first attribute, and grab the text of the second attribute in an HTML file:
--
Edit: Getting closer
I'm not very good at XPath, and am a bit lost at the syntax to 1) find an element based on the value of its first attribute, and grab the text of the second attribute in an HTML file:
<meta name="description" content="Blah"/> <meta name="keywords" content="blah"/> <meta name="classification" content="other"/> description = root.find('./head/meta[@description]') print(description.text)Thank you.
--
Edit: Getting closer
description=root.xpath("//meta[@name='description' and @content]") #BAD print(description.text) #'list' object has no attribute 'text'