Issue
import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
from otp import get_otp
import time
options = webdriver.ChromeOptions()
# options.add_argument("--disable-dev-shm-usage")
# options.add_argument('--enable-javascript')
# options.add_argument('--headless')
# options.add_argument('--no-sandbox')
webdriver_service = Service(ChromeDriverManager().install())
webdriver_service.start()
driver = uc.Chrome(service=webdriver_service, options=options)
there is such a code. After 10 launches, I started getting this error -
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:54585 from session not created: This version of ChromeDriver only supports Chrome version 121 Current browser version is 120.0.6099.227
Any thoughts pls?
Solution
Currently with undetected-chromedriver
, you would need to update the version_main
arg of uc.Chrome()
every time a new version of Chrome comes out. That's not self-sustaining. Alternatively, there's https://github.com/seleniumbase/SeleniumBase with UC Mode, which is basically undetected-chromedriver
with some improvements, such as automatically getting a version of chromedriver that is compatible with your version of Chrome. Set uc=True
to activate UC Mode in a SeleniumBase script. Here's an example:
from seleniumbase import Driver
driver = Driver(uc=True)
There's some documentation about it here: https://github.com/seleniumbase/SeleniumBase/issues/2213
Here's a larger script:
from seleniumbase import Driver
driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
# DO MORE STUFF
driver.quit()
For customizing the reconnect time when loading a URL that has bot detection services, you could swap the get()
line with something like this:
driver.uc_open_with_reconnect("https://nowsecure.nl/#relax", reconnect_time=5)
(The reconnect_time
is the wait time before chromedriver reconnects with Chrome. Before the time is up, a website cannot detect Selenium, but it also means that Selenium can't yet issue commands to Chrome.)
Answered By - Michael Mintz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.