简体   繁体   中英

Can't open chrome in incognito with Python

I want to open a chrome window in incognito mode with python.

I've seen others examples but always open a new tab in normal mode

import webbrowser

    browser_path = 'C:\Program Files\Google\Chrome\Application\chrome.exe --incognito %s'
    webbrowser.get(browser_path)
    webbrowser.open_new('www.google.com')

You need to create a controller object for your browser type (in this case, chrome in incognito mode) using "get" method. Once you have the object, you can call "open_new" method. This is how I did it:

import webbrowser

browser_path = '"C:\Program Files\Google\Chrome\Application\chrome.exe" --incognito %s'
browser = webbrowser.get(browser_path) 
browser.open_new('www.google.com')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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