Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99411

How to scrape Full Name from site using Selenium on Python?

$
0
0

I am pretty new to coding and learning Selenium Webdriver on Python. I have had a lot of help up to this point and I am very close to my desired output.

So far I am able to grab the players Abbreviated Names, the Over/Under data, and the Lines. For example, my current output looks like this:

Player                              Over       Line       Under

A. Radulov                          +127       2.5         -167  
G. Landeskog                        -130       2.5         +100
etc.

I would, however, like the final output to show all of the player's Full Names:

Player                               Over        Line       Under

Alexander Radulov                     +127       2.5         -167  
Gabriel Landeskog                     -130       2.5         +100
etc.

Here is my current code

import pandas as pd
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time

driver=webdriver.Chrome("C:\webdrivers\chromedriver.exe")
driver.maximize_window()
driver.get("https://www.betonline.ag/sportsbook/player-props")
WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"builder")))
time.sleep(2)
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//li[@class='one-third one-third-remove']//a[./b[contains(.,'Over / Under')]]"))).click()
time.sleep(2)




WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div[ng-if='selected.league']"))).click()
time.sleep(2)
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//li[@ng-repeat='league in leagues']/a[.//span[text()='NHL']]"))).click()
time.sleep(2)
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div[ng-if^='selected.game']"))).click()
time.sleep(2)
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//li/a[.//div[text()='All Available']]"))).click()

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[contains(.,'Shots on goal')]"))).click()



player=[]
Over=[]
line=[]
Under=[]
Playersname=WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.XPATH,"//div[@class='div-table__row__cell hard--bottom hard--right ng-scope']//a[@class='ng-binding']")))
for players in Playersname:
    player.append(players.text)

OverAndUnder=WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"a>b.milli.caps.ng-binding")))
count=int(len(OverAndUnder)/2)
x=0
for i in range(count):
    Over.append(OverAndUnder[x].text)
    Under.append(OverAndUnder[x+1].text)
    x=x+2

lines=WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"div[ng-class*='overUnder']>b")))
for l in lines:
    line.append(l.text)

df = pd.DataFrame({"Player":player,"Over":Over,"Line":line, "Under":Under})
print(df)

In order to find the Full name I clicked on a player's name and inspected the data. I did find the correct data but I am not sure how to correctly parse this correctly.

enter image description here

My hope is that the final output will include all of the same data with the exception being the player's full names instead of the abbreviated first names. Thank you in advance for any help or insight that you may offer.


Viewing all articles
Browse latest Browse all 99411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>