Connection refused using PhantomJs

时间:2015-09-01 22:02:11

标签: python selenium phantomjs

I use Selenium + PhantomJS driver in python. It configures likes this:

desired_cap = {
        'phantomjs.page.settings.loadImages' : False,
        'phantomjs.page.settings.resourceTimeout' : 10000,
        'phantomjs.page.settings.userAgent' : '...'
}

self.driver = webdriver.PhantomJS(desired_capabilities=desired_cap)

self.driver.set_window_size(1024, 768)
self.driver.set_page_load_timeout(10)

Than in cycle I request some pages using:

self.driver.get('page-url')

Everything works great for about 5 minutes (~1 get in 2 seconds), after that time I get error:

 <urlopen error [Errno 111] Connection refused>

And it appears not only for get method, but for any method called from self.driver. I think that connection to phantomjs instance drops for some reason and object fails to send commands to it.

phantomjs --version
2.0.1-development

uname -a
Linux wincode 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Everything is running on local machine.

1 个答案:

答案 0 :(得分:2)

禁用加载图片时,似乎问题出现在memory leak of PhantomJS中:

'phantomjs.page.settings.loadImages' : False

所以当我启用图像时,加载问题就消失了。