我不断遇到Web驱动器异常错误,而有时也可以工作
我不断遇到各种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()
I keep getting a variety of WebDriver errors and then randomly it will run properly. How do i fix the error that is happening so that i can run the full version of what i am trying to do?
The latest one was : WebDriverException: unknown error: unexpected command response
(Session info: 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
可能是您已更新了Google Chrome吗?在Google设置 /关于Chrome中检查Google Chrome版本。 eg: My Chrome version is 103.0.5060.66
Download and update Chromedriver to the version of your browser.希望这会有所帮助。
Could it be that you have updated Google Chrome? Check Google Chrome version in Google settings / About Chrome. e.g.: My Chrome version is 103.0.5060.66
Download and update Chromedriver to the version of your browser. Hope this helps.
This is a known issue with 103.0.5060.66
https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121
From the link above here is a possible solution for now:
"Untill the issue is fixed "Downgrade Chrome Version到102“并安装” Selenium Chrome Driver v102“您的脚本将不用任何问题运行,就像我建议的“注释32”今天我尝试过的那样,它没有任何问题”
This is a known issue with 103.0.5060.66
https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121
From the link above here is a possible solution for now:
"Untill the issue is fixed "Downgrade Chrome Version to 102" and install "Selenium Chrome Driver v102" your script will run without any issue, As I had suggested "Comment 32" today I tried it and it worked without any issue"