HtmlUnit硒python Errno 111 [英] HtmlUnit selenium python Errno 111
问题描述
我正在尝试在我的Django
应用程序中将硒与HtmlUnit
一起使用.这是我的程序:
I'm trying to use selenium with HtmlUnit
in my Django
app. This is my procedure:
我从后台开始:java -jar selenium-server-standalone-2.27.0.jar
bg
I start in background: java -jar selenium-server-standalone-2.27.0.jar
bg
我使用以下代码:
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
...
我的问题是,我总是出现urlopen
错误[Errno 111]连接被拒绝."您知道吗?
My problem is that I get always urlopen
error [Errno 111] Connection refused". Have you any idea?
推荐答案
我可以使用独立服务器的最新版本和Selenium python绑定(目前为2.31)运行您的代码而不会出现错误.
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 &
然后从python绑定的版本2开始,您可以使用以下更简单的方法:
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")
只需确保后台服务器确实在运行,请通过打开浏览器并输入url对其进行测试
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
这篇关于HtmlUnit硒python Errno 111的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!