S
S
swww2021-10-31 15:29:01
Python
swww, 2021-10-31 15:29:01

How to get text values ​​using python selenium from SVG?

617e8b9cbb61d216014186.png
There is a site . I am interested in basketball, I choose the championship and the match, statistics appear. I'm trying to get a series of wins and losses using python selenium, circled everything on the screen, I find the desired element through

driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div/div/div[2]/div[1]/div/div[3]/div[2]/div/div[1]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/div')
when you try to print it, it does not print anything, I tried both through the class name and through the selector, everything is the same. When choosing each past game of the game, through get_attribute('title') it displays the date, the name of the teams and the score, but it is necessary that it be exactly V, P and so on, depending on the series of games, so is it possible to somehow get the data values?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-10-31
@swww

When I try to print it, it doesn't print anything.

Wrong xpath
Each svg icon has a tag use, which has its own attribute, which has the value either #icon-loseor #icon-win(it's not hard to guess what it means).
We find all the use tags in the div we need and get its attributes
use_tags = div.find_elements_by_tag_name('use')
print(['W' if use_tag.get_attribute('xlink:href') == '#icon-win' else 'L' for use_tag in use_tags])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question