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

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

问题描述

我使用 Selenium 2 和 python 绑定从我们合作伙伴的站点获取一些数据.但平均而言,我执行此操作需要大约 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天全站免登陆