蟒蛇/硒无痕/私模 [英] Python/Selenium incognito/private mode

查看:857
本文介绍了蟒蛇/硒无痕/私模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到如何使硒打开隐身模式下浏览器中的任何文件。

我必须安装在浏览器中自定义配置文件或?


解决方案

首先,因为默认情况下,启动一个浏览器,用干净,崭新的个人资料,你其实已经私下浏览的。参照:


但你可以严格执行/反正打开无痕/私有模式。

有关铬通<一个href=\"http://peter.sh/experiments/chromium-command-line-switches/#incognito\"><$c$c>--incognito命令行参数:


  

- 隐姓埋名直接导致在隐身模式下启动浏览器。


 硒进口的webdriverchrome_options = webdriver.ChromeOptions()
chrome_options.add_argument( - 改名)司机= webdriver.Chrome(chrome_options = chrome_options)
driver.get('https://google.com')

仅供参考,这里是它会打开:

对于Firefox,请将 browser.privatebrowsing.autostart

 硒进口的webdriverfirefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_ preference(browser.privatebrowsing.autostart,真)司机= webdriver.Firefox(firefox_profile = firefox_profile)

FYI,这对应于以下复选框的设置:

I can not seem to find any documentation on how to make Selenium open the browser in incognito mode.

Do I have to setup a custom profile in the browser or?

解决方案

First of all, since selenium by default starts up a browser with a clean, brand-new profile, you are actually already browsing privately. Referring to:


But you can strictly enforce/turn on incognito/private mode anyway.

For chrome pass --incognito command-line argument:

--incognito Causes the browser to launch directly in incognito mode.

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

FYI, here is what it would open up:

For firefox, set browser.privatebrowsing.autostart to True:

from selenium import webdriver

firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)

driver = webdriver.Firefox(firefox_profile=firefox_profile)

FYI, this corresponds to the following checkbox in settings:

这篇关于蟒蛇/硒无痕/私模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆