Skip to content

Commit 8303840

Browse files
authored
Handle Selenium 4.13 no longer supporting headless (#412)
Selenium does no longer support headless mode for version 4.13 and above. This was added to the docs and a warning is raised if headless mode is enabled for a recent version of Selenium. Also adds a temporary fix for undetected-chromedriver, setting "headless" explicitly to False, such that soccerdata can still be used with recent versions of selenium. Fixes #398
1 parent 7552629 commit 8303840

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

soccerdata/_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import numpy as np
1414
import pandas as pd
1515
import requests
16+
import selenium
1617
import undetected_chromedriver as uc
1718
from dateutil.relativedelta import relativedelta
19+
from packaging import version
1820
from selenium.common.exceptions import WebDriverException
1921

2022
from ._config import DATA_DIR, LEAGUE_DICT, logger
@@ -403,7 +405,16 @@ def _init_webdriver(self) -> "uc.Chrome":
403405
# Start a new driver
404406
chrome_options = uc.ChromeOptions()
405407
if self.headless:
408+
print("Starting ChromeDriver in headless mode.", selenium.__version__)
409+
if version.parse(selenium.__version__) >= version.parse("4.13.0"):
410+
raise ValueError(
411+
"Headless mode is not supported for Selenium 4.13.0 and above. "
412+
"Please downgrade to a lower version of Selenium or set "
413+
"'headless=False'."
414+
)
406415
chrome_options.add_argument("--headless")
416+
else:
417+
chrome_options.headless = False
407418
if self.path_to_browser is not None:
408419
chrome_options.add_argument("--binary-location=" + str(self.path_to_browser))
409420
proxy = self.proxy()

soccerdata/whoscored.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class WhoScored(BaseSeleniumReader):
166166
Path to the Chrome executable.
167167
headless : bool, default: True
168168
If True, will run Chrome in headless mode. Setting this to False might
169-
help to avoid getting blocked.
169+
help to avoid getting blocked. Only supported for Selenium <4.13.
170170
"""
171171

172172
def __init__(

0 commit comments

Comments
 (0)