Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

django - HtmlUnit selenium python Errno 111

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...