简体   繁体   English

无法使用 Python 以隐身方式打开 chrome

[英]Can't open chrome in incognito with Python

I want to open a chrome window in incognito mode with python.我想用python以隐身模式打开一个chrome窗口。

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.您需要使用“get”方法为您的浏览器类型(在本例中为隐身模式下的 chrome)创建一个控制器对象。 Once you have the object, you can call "open_new" method.一旦你有了对象,你就可以调用“open_new”方法。 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')

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

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