不想在Selenium WebDriver中的Firefox上加载图像和CSS渲染-Python [英] Do not want the Images to load and CSS to render on Firefox in Selenium WebDriver - Python

查看:279
本文介绍了不想在Selenium WebDriver中的Firefox上加载图像和CSS渲染-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有python绑定的Selenium 2从我们合作伙伴的站点中获取一些数据.但是平均而言,执行此操作大约需要13秒钟.

I am using Selenium 2 with python bindings to fetch some data from our partner's site. But on an average it's taking me around 13 secs to perform this operation.

我正在寻找一种禁用图像CSS和Flash等的方法.

I was looking for a way to disable the images css and flash etc.

我正在使用Firefox 3.6和pyvirtualdisplay来防止打开Firefox窗口.任何其他加快Firefox的优化也将有所帮助.
我已经尝试过network.http.*选项,但没有太大帮助.

I am using Firefox 3.6 and also using pyvirtualdisplay to to prevent opening of firefox window. Any other optimization to speed up firefox will be also helpful.
I have already tried network.http.* options but does not help much.

并设置permissions.default.image = 2

推荐答案

我已经找到一种防止Firefox加载CSS,图像和Flash的方法.

I have figured out a way to prevent Firefox from loading CSS, images and Flash.

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

def disableImages(self):
    ## get the Firefox profile object
    firefoxProfile = FirefoxProfile()
    ## Disable CSS
    firefoxProfile.set_preference('permissions.default.stylesheet', 2)
    ## Disable images
    firefoxProfile.set_preference('permissions.default.image', 2)
    ## Disable Flash
    firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                  'false')
    ## Set the modified profile while creating the browser object 
    self.browserHandle = webdriver.Firefox(firefoxProfile)

再次感谢@Simon和@ernie的建议.

Thanks again @Simon and @ernie for your suggestions.

这篇关于不想在Selenium WebDriver中的Firefox上加载图像和CSS渲染-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆