PhantomJS 1.8与python上的Selenium。如何阻止图像?

时间:2013-03-12 20:30:11

标签: python selenium phantomjs

有没有办法在Selenium上配置PhantomJS webdriver以不加载图像?我知道如果我直接使用phantomjs,我可以用--load-images=no启动它并且它不会加载图像,但我如何通过Selenium和Python配置?

UPDATE 尝试以下方法:

args = {
    'desired_capabilities': {
         'loadImages': False
     }
}
driver = webdriver.PhantomJS(**args)

没有成功......

2 个答案:

答案 0 :(得分:18)

你为什么不尝试webdriver.PhantomJS(service_args=['--load-images=no'])

答案 1 :(得分:4)

编辑:传递参数公开,请参阅下面提到的相同答案,了解如何操作

使用selenium的webdriver的init ... I have worked around that by monkey patching the PhantomJS executer目前没有向phantomjs传递参数。检查答案是否将service_args更改为以下内容:

service_args += [
    '--load-images=no',
]

你也可以选择自己启动phantomjs服务器,只需使用以下调用指向已在8080端口运行的phantomjs

# init the webdriver
self.driver = webdriver.PhantomJS(port=8080)