selenium设置页面不加载图片,可以加快页面打开速度!
方法如下:
import selenium.webdriver as wb
#下面的路径是chromedriver所在路径
chrome_driver=r'E:anacondaLibsite-packagesseleniumwebdriverchromechromedriver.exe'
chrome_options = wb.ChromeOptions()
prefs = {'profile.managed_default_content_settings.images': 2}
chrome_options.add_experimental_option('prefs',prefs)
br = wb.Chrome(executable_path=chrome_driver,options=chrome_options)
随便打开一个网页,例如百度:
url = 'https://www.baidu.com/'
br.get(url=url)
让我看下效果:
![70d2c91440005a8a9ff3c2a98347b2e6.png](https://i-blog.csdnimg.cn/blog_migrate/1d295c5e4d4542626cf331b9bcc3de9d.jpeg)
对比正常打开,确实没有加载图片
![ac23b0a7259013c05b69ec1a62d8b403.png](https://i-blog.csdnimg.cn/blog_migrate/6d62673f3d4fdd71e6436a5efa567505.jpeg)
成功!