HtmlUnit selenium python Errno 111

早过忘川 提交于 2019-12-12 03:46:37

问题


I'm trying to use selenium with HtmlUnit in my Django app. This is my procedure:

I start in background: java -jar selenium-server-standalone-2.27.0.jar bg

I use this code:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver

url = "www.google.com"
driver = WebDriver("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.HTMLUNITWITHJS)
driver.get(url)
text = driver.page_source
...

My problem is that I get always urlopen error [Errno 111] Connection refused". Have you any idea?


回答1:


I can run your code without errors with the last version of the stand alone server and the selenium python bindings (2.31 at the moment).

I usually start the server in background:

java -jar selenium-server-standalone-2.31.0.jar &

Then starting from version 2 of the python bindings your can use the simpler:

import selenium.webdriver as webdriver
driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS)
driver.get("http://www.google.com")

Just make sure the background server is actually running, test it by opening a browser and typing the url

http://127.0.0.1:4444/wd/hub/static/resource/hub.html


来源:https://stackoverflow.com/questions/14546291/htmlunit-selenium-python-errno-111

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