Python_Selenium之瀏覽器封裝_去掉瀏覽器受到自動化控制橫條顯示及去掉是否記住密碼彈窗


封裝如下:

from selenium import webdriver
from common.config_utils import config
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

def set_driver():
chrome_options = webdriver.ChromeOptions()
prefs = {"": ""}
prefs["credentials_enable_service"] = False
prefs["profile.password_manager_enabled"] = False
chrome_options.add_experimental_option("prefs", prefs) ##關掉密碼彈窗
chrome_options.add_argument('--disable-gpu') # 谷歌文檔提到需要加上這個屬性來規避bug
chrome_options.add_argument('lang=zh_CN.UTF-8') # 設置默認編碼為utf-8
chrome_options.add_experimental_option('useAutomationExtension', False) # 取消chrome受自動控制提示
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) # 取消chrome受自動控制提示

driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
return driver


 

 

實現結果:

沒有了受到自動化控制的橫條顯示,也沒有了記住密碼的彈窗。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM