Home > Software engineering >  start Selenium chrome driver minimized (or equivalent)
start Selenium chrome driver minimized (or equivalent)

Time:09-18

I'm making a web scraping program, but to keep from being blocking by anti-scraping software I gotta keep the driver out of headless mode. sometimes I also need to restart the driver to clear the cookies, so whenever it opens back up I minimize it immediately, but it still gets in the way of whatever Im doing for about a second, and this program runs for hours so its incredibly annoying

Im thinking theres probably something I can add like driver.add_option("start in minimized") or driver.add_option("start in off screen") (equivalent to driver.set_window_position(-2000,0) but before the driver opens

does anyone know of an options setting I can add for this?

heres what my current code looks like, though this is more of a feature question than a bug fixing problem

import undetected_chromedriver.v2 as uc

def start_uc():
    '''opens a UC chrome driver with prefered settings'''
    options = uc.ChromeOptions()
    # just some options passing in to skip annoying popups
    options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
    return uc.Chrome(options=options)

driver = start_uc()
driver.minimize_window()

for item in list:
    #scrape item info

    if blocked from page:
        driver.close()
        driver = start_uc()
        driver.minimize_window()

CodePudding user response:

Unfortunately there is no such option / capability.
You can set driver to start maximized with

options.add_argument("start-maximized")

But there is no such option as options.add_argument("start-minimized").
As you mentioned, you can minimize the driver screen immediately after it's creating with driver.set_window_position(-2000,0) but, again, this will be applied only after the driver is opened.

  • Related