简体   繁体   English

我无法在Selenium和Python上使用HTMLUnit驱动程序

[英]I'm unable to use HTMLUnit driver with Selenium and Python

I tried that : 我试过了

from selenium import webdriver
driver=webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNIT)
driver.get('http://www.google.com')

I have no error but when I made a research with for example, BeautifulSoup, the program never close and so he never return me a value. 我没有错误,但是当我使用例如BeautifulSoup进行研究时,该程序从未关闭,因此他从未向我返回任何值。

You need to run the Selenium Java server for this to work, since HTMLUnit is implemented on the Java side. 由于HTMLUnit是在Java端实现的,因此您需要运行Selenium Java服务器才能使其正常工作。 So download it and run: 因此,下载并运行:

java -jar selenium-server-standalone-3.6.0.jar

Then update your code to point to it (you need to set version and platform to None): 然后更新您的代码以指向它(您需要将版本和平台设置为“无”):

from selenium import webdriver
cap = {'platform': None, 'browserName': 'htmlunit', 'version': None}
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=cap)
driver.get("https://google.com")
print(driver.page_source)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM