selelium中使用两种方法使得打开浏览器不加载图片

xiaoxiao2021-02-28  11

第一种:使用webdriver.Chrome这个方法使得打开界面不加载图片

# -*- coding:utf-8 -*- __author__ = 'bobby' from selenium import webdriver chrome_opt = webdriver.ChromeOptions() prefs = {"profile.managed_default_content_setting.images":2} chrome_opt.add_experimental_option("prefs",prefs) browser = webdriver.Chrome(executable_path="C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe") browser.get("www.taobao.com")

第二种:使用phantom.js打开网页不加载网页图片

# -*- coding:utf-8 -*- __author__ = 'bobby' from selenium import webdriver #phantomjs,没有界面的浏览器,多进程情况下phantomjs性能会下降比较严重 browser = webdriver.PhantomJS(executable_path="C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe") browser.get("www.taobao.com") print(browser.page_source) browser.quit()

转载请注明原文地址: https://www.6miu.com/read-750305.html

最新回复(0)