如何使用 Python Selenium WebDriver 在隱身/隱私模式下開啟瀏覽器視窗?


使用 ChromeOptions 類,我們可以使用 Python 中的 Selenium webdriver 以隱身/隱私模式開啟瀏覽器視窗。我們必須建立一個 ChromeOptions 類的物件。

然後,將方法 add_argument 應用到該物件並傳遞引數--incognito 作為引數。最後,此資訊必須傳遞到 webdriver 物件。

語法

c = webdriver.ChromeOptions()
c.add_argument("--incognito")

示例

from selenium import webdriver
#object of ChromeOptions class
c = webdriver.ChromeOptions()
#incognito parameter passed
c.add_argument("--incognito")
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe",options=c)
driver.implicitly_wait(0.5)
#launch URL
driver.get("https://tutorialspoint.tw/tutor_connect/index.php")

輸出

更新日期:2021-04-03

8 千+

開啟您的 職業

完成課程獲得認證

入門
廣告