PhantomJS 1.8 with Selenium on python. How to block images?

倾然丶 夕夏残阳落幕 提交于 2020-01-01 08:38:31

问题


Is there a way to configure PhantomJS webdriver on Selenium to do not load images? I know if I use phantomjs directly, I can start it with --load-images=no and it won't load the images, but how can I configure that via Selenium and Python?

UPDATE Tried the following:

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

No success...


回答1:


Why are you not trying webdriver.PhantomJS(service_args=['--load-images=no']) ?




回答2:


EDIT: passing arguments is exposed, see the same answer mentioned below for how to do it

Passing arguments to phantomjs is not currently exposed with selenium's webdriver's init ... I have worked around that by monkey patching the PhantomJS executer. Check that answer changing service_args to the following:

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

You could also opt to start the phantomjs server yourself, and just use the following call to point to an already running phantomjs at port 8080

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


来源:https://stackoverflow.com/questions/15371495/phantomjs-1-8-with-selenium-on-python-how-to-block-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!