Python Forum

Full Version: Get the attributes value with xPath
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I would like to get the value from the data-score attribute within the <span>-element.
<span class="index__stars__2ads4 index__large__1Ez3-" data-fillcolor="butterscotch" data-score="2.5"></span>

The following line returns an empty list:
score = tree.xpath('//span[@class="index__stars__2ads4 index__large__1Ez3-"]//data-score/text()')
What am I doing wrong here? Rolleyes

Greetings
Try:
tree.xpath("//*[@class='index__stars__2ads4 index__large__1Ez3-']/@data-score")