Python Forum
Get the attributes value with xPath - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Get the attributes value with xPath (/thread-37280.html)



Get the attributes value with xPath - vulturas - May-22-2022

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


RE: Get the attributes value with xPath - snippsat - May-22-2022

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