【问题标题】:I'm unable to use HTMLUnit driver with Selenium and Python我无法将 HTMLUnit 驱动程序与 Selenium 和 Python 一起使用
【发布时间】:2017-10-31 13:08:27
【问题描述】:

我试过了:

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

我没有错误,但是当我使用 BeautifulSoup 进行研究时,程序永远不会关闭,因此他永远不会返回值。

【问题讨论】:

  • 请澄清您的具体问题或添加其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。请参阅How to Ask 页面以获得澄清此问题的帮助。

标签: python selenium beautifulsoup htmlunit


【解决方案1】:

您需要运行 Selenium Java 服务器才能使其工作,因为 HTMLUnit 是在 Java 端实现的。所以下载并运行:

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

然后更新您的代码以指向它(您需要将版本和平台设置为无):

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)

【讨论】:

  • 感谢您的帮助。它仍然没有返回给我,我认为当我启动 java 服务器时有问题,这里是 cmd 屏幕(prntscr.com/h4hnepprntscr.com/h4hnyi
  • 第一个错误是端口已在使用中,您在 4444 上运行了其他东西吗?您可以尝试使用 -port 4445 启动它并在 command_executor 字符串中使用 4445 吗?
  • 它可以工作,但是当我尝试从不同的网站获取源代码时 - jeuxvideo.com - 它不会返回任何东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-24
  • 2015-07-24
  • 1970-01-01
  • 2017-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多