Bub*_*ast 38 python browser selenium incognito-mode selenium-webdriver
我似乎找不到任何关于如何让Selenium以隐身模式打开浏览器的文档.
我是否必须在浏览器中设置自定义配置文件或?
ale*_*cxe 54
首先,由于selenium默认情况下启动的浏览器具有干净,全新的配置文件,因此您实际上已经私下浏览了.参考:
但无论如何,您可以严格执行/启用隐身/私密模式.
对于chrome pass --incognito命令行参数:
--incognito导致浏览器以隐身模式直接启动.
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
仅供参考,以下是开放的内容:

对于firefox,设置browser.privatebrowsing.autostart为True:
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(firefox_profile=firefox_profile)
Run Code Online (Sandbox Code Playgroud)
仅供参考,这对应于设置中的以下复选框:

小智 13
注意: chrome_options 现在已弃用。我们可以使用 'options' 而不是 chrome_options
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
driver = webdriver.Chrome(options=options)
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
我已经使用 ChromeOptions 和 FirefoxOptions 成功地在隐身/私人模式下启动了 Chrome 和 Firefox,使用 Java 中的代码片段如下:
//For Firefox
FirefoxOptions options = new FirefoxOptions();
options.addArguments("-private");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("moz:firefoxOptions",options);
//For Chrome
ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
caps.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39822 次 |
| 最近记录: |