<p>youtube上有一个非常好的教程(这个家伙教你如何使用这个非常有趣的饼干点击游戏);它具有try/except功能,下面是我访问selenium项目的转到。我能够让它与下面显示的代码工作,希望这有助于</p>
<pre><code>from selenium import webdriver
from time import sleep
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get('https://www.wikiloc.com/wikiloc/start.do')
driver.find_element_by_name('email').send_keys('testacount852')
driver.find_element_by_name('password').send_keys('49Vchu4njDrrT7.')
driver.find_element_by_id('submit-button').click()
time.sleep(10)
driver.get("https://www.wikiloc.com/trails/outdoor/france/brittany")
links = []
temp_links = []
names = []
temp_names = []
for _ in range(4):
temp = driver.find_elements_by_css_selector('a.trail-title.dont-break-out')
temp_links = [x.get_attribute('href') for x in temp]
temp_names = [x.text for x in temp]
links = links+temp_links
names = names+temp_names
try:
driver.find_element_by_class_name('next').click()
time.sleep(2)
except:
break
for link in links:
driver.get(link)
try:
downloadbutton = WebDriverWait(driver,15).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#download-button")))
downloadbutton.click()
except:
print("Couldn't find the download button")
pass
time.sleep(4)
driver.find_element_by_class_name('active').click()
time.sleep(4)
driver.find_element_by_xpath("/html/body/main/div/div[2]/div/div[1]/div/div[2]/div/div[2]/form/div[2]/input").click()
time.sleep(4)
df['Names'] = pd.Series(names)
df['Links'] = pd.Series(links)
df.to_csv('test1.csv')
driver.close()
</code></pre>