蟒蛇/硒无痕/私模 [英] Python/Selenium incognito/private mode
问题描述
我似乎无法找到如何使硒打开隐身模式下浏览器中的任何文件。
我必须安装在浏览器中自定义配置文件或?
首先,因为硒
默认情况下,启动一个浏览器,用干净,崭新的个人资料,你其实已经私下浏览的。参照:
但你可以严格执行/反正打开无痕/私有模式。
有关铬通<一个href=\"http://peter.sh/experiments/chromium-command-line-switches/#incognito\"><$c$c>--incognito$c$c>命令行参数:
- 隐姓埋名
直接导致在隐身模式下启动浏览器。
块引用>硒进口的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:
- Python - Start firefox with Selenium in private mode
- How might I simulate a private browsing experience in Watir? (Selenium)
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
toTrue
: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屋!