简体   繁体   English

启动 Selenium 铬驱动程序最小化(或等效)

[英]start Selenium chrome driver minimized (or equivalent)

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.我正在制作一个 web 抓取程序,但为了避免被反抓取软件阻塞,我必须让驱动程序处于无头模式。 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有时我还需要重新启动驱动程序以清除 cookies,所以每当它打开备份时,我都会立即将其最小化,但它仍然会妨碍我做的任何事情大约一秒钟,而且这个程序运行了几个小时,所以它非常烦人

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我想可能我可以添加一些东西,比如driver.add_option("start in minimized")driver.add_option("start in off screen") (相当于driver.set_window_position(-2000,0)但在驱动程序打开之前

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()

Unfortunately there is no such option / capability.不幸的是,没有这样的选择/能力。
You can set driver to start maximized with您可以将driver设置为开始最大化

options.add_argument("start-maximized")

But there is no such option as options.add_argument("start-minimized") .但是没有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.正如您所提到的,您可以在使用driver.set_window_position(-2000,0)创建驱动程序屏幕立即最小化它,但同样,这只会在driver打开后应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM