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()
CodePudding user response:
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"
CodePudding user response:
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.