Home > Software design >  How to get hover-information with selenium / beautifulsoup?
How to get hover-information with selenium / beautifulsoup?

Time:04-17

i would like to get the data form this hover-information on this site: enter image description here

When i inspect the code i can´t see any informations of that? Is there any way to get this information scraped using selenium / beautiful soup?

CodePudding user response:

You just need hover over the name using ActionsChain and then you can extract the text off of from the tooltip.

Code:

driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://www.pferdewetten.de/race/17350803")

ActionChains(driver).move_to_element(wait.until(EC.visibility_of_element_located((By.XPATH, "//span[starts-with(@class,'ParticipantInfoItem_info_horseName')]")))).perform()
print(wait.until(EC.presence_of_element_located((By.XPATH, "//div[starts-with(@class,'ParticipantInfoItem_infoContainer--')]//div[starts-with(@class,'Tooltip')]"))).get_attribute('innerText'))

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

Output:

Jumby Bay (2019)
Herkunft:
Frankreich
Vater:
Uriel Speed
Mutter:
Norvege
Besitzer:
Ecurie A.B Racing

Process finished with exit code 0

PS: In order to hover over each and every name, you should first take them into a list and then in a loop you should ideally perform hovering and and extracting the text in same way.

CodePudding user response:

As @Sayse stated that the desired data is also dynamically loaded from api calls json response as GET method and you also can grab data easily using only requests module and You have to add authentication key as header that's sent to api response in Request Headers.

import requests
headers={"Authorization2": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd3d3LnBmZXJkZXdldHRlbi5kZVwvIiwiYXVkIjoiaHR0cHM6XC9cL3d3dy5wZmVyZGV3ZXR0ZW4uZGVcLyIsImlhdCI6MTY1MDEyODM5OCwiZXhwIjoxNjUwMTMwMTk4LCJpcCI6IjM3LjExMS4yMDUuMTQ0IiwiY28iOiJQRlciLCJjdHkiOiJCRCIsImxuZyI6Imdlcm1hbiIsImNhblJlZ2lzdGVyIjp0cnVlfQ.NQr1B6rVx5T39Zm_78959KX0bNufzWGNDQ7_Bq_dMFI"}
api_url = "https://www.pferdewetten.de/data/racecard/get/17350803"
jsonData=requests.get(api_url,headers=headers).json()

for horse in jsonData['data']['participants']:
    horse_name=horse['horse_name']
    print(horse_name)
    

Output:

Jumby Bay
Juliana Filo
Jade De Bertrange
Jaya Du Bessy
Jenny Gold
Jeny de Gouye
Jabelone
Jenesys Vallee
Jarny De Bertrange
Jordana Du Fer
Jazzy Du Liamone
Jismie Griff
Jelfa
Just Beautiful
  • Related