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

猜你喜欢

转载自www.cnblogs.com/easy-test/p/12119251.html
今日推荐