问题描述
我使用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和闪存等。
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使用Python测试中加载图像和在Firefox上呈现CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!