我正在尝试在 Rotogrinder/Resultdb 上抓取特定日期参加比赛的所有团队。但是,我刚刚意识到,当被抓取的比赛条目少于 50 个(只有一页)时,我的代码会停留在循环中,因为我通常使用下一步按钮退出该循环。这是我的代码:
*** 我改三行直接去比赛,出现问题。
#Packages:
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 pandas as pd
import time
from selenium.common.exceptions import NoSuchElementException
# Driver
chromedriver =("C:/Users/Michel/Desktop/python/package/chromedriver_win32/chromedriver.exe")
driver = webdriver.Chrome(chromedriver)
# DF taht will be use later
results = pd.DataFrame()
best_lineups=pd.DataFrame()
opti_lineups=pd.DataFrame()
#For loop over all DATES:
CALENDAR=[]
CALENDAR.append("2017-10-04")
CALENDAR.append("2017-10-05")
for d in CALENDAR:
driver.get("https://rotogrinders.com/resultsdb/date/"+d+"/sport/4/")
time.sleep(10)
try:
contest= driver.find_element_by_xpath("//*[@id='root']/div/main/main/div[2]/div[3]/div/div/div[1]/div/div/div/div/div[3]")
contest.click()
list_links = driver.find_elements_by_tag_name('a')
hlink=[]
for ii in list_links:
hlink.append(ii.get_attribute("href"))
sub="https://rotogrinders.com/resultsdb"
con= "contest"
contest_list=[]
for text in hlink:
if sub in text:
if con in text:
contest_list.append(text)
# comment next two lines and replace by following three to get directly to where the code keep looping
# for c in contest_list:
# driver.get(c)
c=contest_list[3:5]
for a in c:
driver.get(a)
n=1
while n<100:
n+=1
time.sleep(10)
我怎么能解决这个问题?
倚天杖
回首忆惘然
相关分类