Extract correct chrome version from exception

This commit is contained in:
Tanner Collin 2023-11-01 19:10:19 +00:00
parent 34f0444de7
commit ba630b6fb9

View File

@ -1,10 +1,11 @@
import time import time
import traceback
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException, WebDriverException
from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as uc import undetected_chromedriver as uc
@ -17,7 +18,22 @@ chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized') chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--no-sandbox')
driver = uc.Chrome(service=ser, options=chrome_options, version_main=116)
try:
driver = uc.Chrome(service=ser, options=chrome_options)
except WebDriverException as e:
print('Wrong chrome driver version, extracting correct version...')
tb = traceback.format_exc()
version_string = tb.split('Current browser version is ')[1]
major_version = version_string.split('.')[0]
print('Trying version:', major_version)
chrome_options = uc.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox')
driver = uc.Chrome(service=ser, options=chrome_options, version_main=int(major_version))
try: try:
driver.get('https://sensors.dns.t0.vc') driver.get('https://sensors.dns.t0.vc')