Closed
Description
SeleniumBase UC Mode needs a video tutorial
There should first be a prelude on how sites detect Selenium in general.
Then there should be an explanation on how automation frameworks can avoid being detected by websites with anti-bot services.
Key things that Selenium frameworks need to do in order to avoid getting detected:
- Modify chromedriver to rename chromedriver-specific variables that appear in the Chrome DevTools console.
- Launch Chrome before attaching chromedriver to it. (Don't use chromedriver to launch Chrome directly.)
- Don't use Chrome options that are specific to Selenium (or ones that are generally only used with Selenium).
- If using headless Chrome, make sure that you change
HeadlessChrome
toChrome
in the User Agent String. - If specifying a custom
user_data_dir
, make sure that the folder is never used with non-UC-Mode Chrome. - Disconnect chromedriver temporarily from Chrome before loading websites that try to detect chromedriver.
When all preventative measures are done correctly, Selenium should be able to enter websites appearing human:
Here are some existing examples that use --uc
mode:
- https://github.com/seleniumbase/SeleniumBase/blob/master/examples/verify_undetected.py
- https://github.com/seleniumbase/SeleniumBase/blob/master/examples/uc_cdp_events.py
- https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_uc_mode.py
Here's a raw driver example:
from seleniumbase import Driver
import time
driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(6)
driver.quit()