【发布时间】:2022-01-16 16:06:14
【问题描述】:
这个问题是在 6 月 (Assistance needed scraping a site with Selenium in Python) 提出的,我正在使用从那时起的代码,但遇到了问题。我认为PP网站已经发生了变化。这是我更新的代码,在单击 Fantasy Score 部分时似乎遇到了错误。该项目的目标只是从NBA球员那里获得幻想分数
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import chromedriver_binary
# Assign PrizePicks URL
driver = webdriver.Chrome()
PATH = "C:\Program Files (x86)\chromedriver.exe"
############## PRIZEPICKS ################################################
#
url = "https://app.prizepicks.com/"
driver.get(url)
#this is to get rid of the pop-up box that shows after you Selenium opens the prizepicks page
driver.find_element(By.CLASS_NAME,"close").click()
#Selecting NBA
driver.find_element(By.XPATH, "//div[@class='name'][normalize-space()= 'NBA']").click()
#Clicking the Fantasy Score tab
driver.find_element(By.XPATH, "//div[@class='stat stat-active'][normalize-space()='Fantasy Score']").click()
driver.find_element(By.XPATH, "//div[@class='segment-selector-button']").click()
projections = WebDriverWait(driver, 20).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".projection")))
#creating a list of the players names and fantasy scores to be collected
nbaPlayers = []
for projection in projections:
names = projection.find_element_by_xpath('.//div[@class="name"]').text
points= projection.find_element_by_xpath('.//div[@class="presale-score"]').get_attribute('innerHTML')
print(names, points)
players = {
'Name': names,
'FantasyPoints': points,
}
nbaPlayers.append(players)
#Put the list in a dataframe
df = pd.DataFrame(nbaPlayers)
print(df)
driver.quit()
【问题讨论】:
标签: python selenium selenium-webdriver