Вот код ниже:
Код: Выделить всё
from path import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import pandas as pd
import undetected_chromedriver as uc
############################################################################
# Initialize the WebDriver
driver = uc.Chrome()
driver.maximize_window() # Open the window in full screen mode
############################################################################
# Scraping PrizePicks
driver.get("https://app.prizepicks.com/")
time.sleep(5)
# Waiting and closes popup
WebDriverWait(driver, 15).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "close")))
time.sleep(5)
driver.find_element(By.XPATH, "/html/body/div[3]/div[3]/div/div/button").click()
time.sleep(3)
# Creating tables for players
ppPlayers = []
# It will click CS2 tab, if you want to scrape a different sport, change 'CS2' to the sport of your liking.
driver.find_element(By.XPATH, "//div[@class='name'][normalize-space()='CS2']").click()
time.sleep(3)
# Waits until stat container element is viewable
stat_container = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "stat-container")))
# Finding all the stat elements within the stat-container. (In this case, it's Map 1-2 Kills, Headshots, etc.)
categories = driver.find_element(By.XPATH, "//div[@role='button'][normalize-space()='MAPS 1-2 Headshots']").click()
projectionsPP = (By.CSS_SELECTOR, ".projection")
wait = WebDriverWait(driver, 25)
element_wait = wait.until(EC.presence_of_all_elements_located(projectionsPP))
# Creating tables for players
ppPlayers = []
############################################################################
# Data Scraping Automation begins here
for projection in projectionsPP:
names = projection.find_element_by_xpath('.//div[@class="name"]').text
value = projection.find_element_by_xpath('.//div[@class="presale-score"]').get_attribute('innerHTML')
proptype = projection.find_element(By.CLASS_NAME, "text").get_attribute('innerHTML')
players = {
'Name': names,
'Value': value,
'Prop': proptype.replace("", "")
}
ppPlayers.append(players)
dfProps = pd.DataFrame(ppPlayers)
dfProps.to_csv('CS2 Props.csv')
print("PrizePicks Props Offered: ", '\n')
print(dfProps)
print('\n')
driver.quit()
Код: Выделить всё
projectionsPP = (By.CSS_SELECTOR, ".projection")
wait = WebDriverWait(driver, 25)
element_wait = wait.until(EC.presence_of_all_elements_located(projectionsPP))
Подробнее здесь: https://stackoverflow.com/questions/784 ... -cs2-props