我正在使用Selenium 2和python绑定从我们的合作伙伴网站获取一些数据.但平均而言,我需要大约13秒才能执行此操作.
我正在寻找一种方法来禁用图像css和flash等.
我正在使用Firefox 3.6并使用pyvirtualdisplay来防止打开firefox窗口.任何其他优化加速Firefox也将有所帮助.
我已经尝试过network.http.*
选项,但没有多大帮助.
并且还设置了 permissions.default.image = 2
因为Webdriver在进入下一行之前等待整个页面加载,我认为禁用图像,css和javascript会加快速度.
from selenium import webdriver
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)
Run Code Online (Sandbox Code Playgroud)
我从stackoverflow获取代码不希望加载图像和使用Python在Selenium WebDriver测试中在Firefox上渲染CSS
但是当我补充说
driver = webdriver.Firefox()
driver.get("http://www.stackoverflow.com/")
Run Code Online (Sandbox Code Playgroud)
到最后,它仍然加载图像:/