【发布时间】:2022-08-08 21:08:56
【问题描述】:
我不断收到各种 WebDriver 错误,然后随机它会正常运行。如何修复正在发生的错误,以便我可以运行我正在尝试做的完整版本?
最新的是:WebDriverException:未知错误:意外的命令响应 (会话信息:chrome=103.0.5060.66)
from selenium import webdriver
import time
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
PATH = \"C:\\Program Files (x86)\\Chrome\\chromedriver_win32\\chromedriver.exe\"
driver = webdriver.Chrome(PATH)
driver.maximize_window()
ytournaments = [\'/dpworld-tour/abu-dhabi-hsbc-championship-2021/\', \'/dpworld-tour/omega-dubai-desert-classic-2021/\']
roundids = [1, 2, 3, 4]
for tournamentid in ytournaments:
for roundid in roundids:
page = driver.get(f\"https://www.europeantour.com{tournamentid}leaderboard?holebyhole=true&round={roundid}\")
time.sleep(10)
html = driver.page_source
soup = BeautifulSoup(html, \'lxml\')
Tour = \'European Tour\'
Year = \'2021\'
tournamentm = soup.find(\'h1\', class_=\'event-hero__title\').text
tournament = tournamentm.strip()
coursem = soup.find(\'p\', class_=\'event-hero__location\').text
course = coursem.strip()
datem = soup.find(\'p\', class_=\'event-hero__date\').text
date = datem.strip()
dfs = pd.read_html(driver.page_source)
df = dfs[0]
ndf = np.squeeze(dfs)
data = pd.DataFrame(ndf)
data[\"tournament\"] = tournament
data[\"course\"] = course
data[\"date\"] = date
data[\"roundid\"] = roundid
data[\"Tour\"] = Tour
data[\"Year\"] = Year
filename = f\'{tournament}_{roundid}_{Year}.csv\'
data.to_csv(filename)
driver.quit()
标签: python selenium selenium-webdriver selenium-chromedriver webdriver