You need to hover to an element, then wait for data to appear and get its text:
Here is the snippet for the first game from the list. To get all games you will need another loop.
I am using ActionChains
to hover on element. Finding locators for this site was not easy even for me.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
driver.get("https://osu.ppy.sh/beatmapsets?m=0")
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".beatmapsets__items-row:nth-of-type(1)>.beatmapsets__item:nth-of-type(1)")))
games = driver.find_element_by_css_selector(".beatmapsets__items-row:nth-of-type(1) .beatmapsets__item:nth-of-type(1) .beatmapset-panel__info-row--extra")
actions = ActionChains(driver)
actions.move_to_element(games).perform()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".beatmaps-popup__group")))
levels = driver.find_elements_by_css_selector(".beatmaps-popup__group .beatmaps-popup-item__col.beatmaps-popup-item__col--name.u-ellipsis-overflow")
for level in levels:
print(level.text)
Output:
Hinsvar's Hard
Zelqurre's Insane
Amamir's Shining Stars
For iteration through a list of levels use this css selector:
.beatmapsets__items-row:nth-of-type(1) .beatmapsets__item:nth-of-type(1) .beatmapset-panel__info-row--extra
And iterate this locator:
.beatmapsets__items-row:nth-of-type(1) .beatmapsets__item:nth-of-type(1) .beatmapset-panel__info-row--extra,
.beatmapsets__items-row:nth-of-type(2) .beatmapsets__item:nth-of-type(1) .beatmapset-panel__info-row--extra
Update:
To get scores use:
scores= driver.find_elements_by_css_selector(".beatmaps-popup__group .beatmaps-popup-item__col.beatmaps-popup-item__col--difficulty")
for score in scores:
print(score.text)
The output will be:
2.58
3.46
4.55
4.90
5.97
Also, check this answer on how to put results in one list: Trouble retrieving elements and looping pages using next page button
And finally read here about css selectors: https://www.w3schools.com/cssref/css_selectors.asp
I usually prefer using them because they are shorter.