selenium 自動允許falsh加載方法


from selenium import webdriver
from selenium.webdriver.chrome.options import Options

prefs = { "profile.managed_default_content_settings.images": 1, "profile.content_settings.plugin_whitelist.adobe-flash-player": 1, "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1, } chrome_options = Options() chrome_options.add_argument('--no-sandbox')#解決DevToolsActivePort文件不存在的報錯 chrome_options.add_argument('window-size=1920x1080') #指定瀏覽器分辨率 chrome_options.add_argument('--disable-gpu') #谷歌文檔提到需要加上這個屬性來規避bug #chrome_options.add_argument('--hide-scrollbars') #隱藏滾動條, 應對一些特殊頁面 #chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加載圖片, 提升速度 chrome_options.add_argument('--headless') #瀏覽器不提供可視化頁面. linux下如果系統不支持可視化不加這條會啟動失敗 chrome_options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" #手動指定使用的瀏覽器位置 chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome()


免責聲明!

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



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