如何使用Python绑定在SeleniumWebDriver中加载HtmlUnit驱动程序?
我从Selenium IDE导出选项中提取了此Python代码,并将如何使用Python绑定在SeleniumWebDriver中加载HtmlUnit驱动程序?,python,selenium,selenium-webdriver,webdriver,web-scraping,Python,Selenium,Selenium Webdriver,Webdriver,Web Scraping,我从Selenium IDE导出选项中提取了此Python代码,并将self.driver=webdriver.Firefox()替换为HtmlUnitDriver(),但它无法工作,因为我有一个错误: AttributeError: 'module' object has no attribute 'HtmlUnitDriver' 代码是: from selenium import webdriver from selenium.webdriver.common.by import By f
self.driver=webdriver.Firefox()
替换为HtmlUnitDriver(),但它无法工作,因为我有一个错误:
AttributeError: 'module' object has no attribute 'HtmlUnitDriver'
代码是:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class Scrape(unittest.TestCase):
def setUp(self):
self.driver = webdriver.HtmlUnitDriver()
self.driver.setJavascriptEnabled(true)
self.driver.implicitly_wait(30)
self.base_url = "http://www.google.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_scrape(self):
driver = self.driver
....
你能告诉我我做错了什么吗?我想用HtmlUnit而不是firefox来看看我是否能用更少的资源更快地实现我的目标。如果可能的话,我需要激活Javascript。如果可能的话,您能告诉我从文档中获取这些信息的位置吗,因为我找不到这些信息?不确定,但是只有在您使用java版本时,AFAIK HtmlUnitDriver才可用 webdriver的开发。如果要在python中使用htmlunit驱动程序,需要启动独立服务器
java -jar selenium-server-standalone-x.x.x.jar
然后通过远程服务器连接到使用
from selenium import webdriver
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT)
//or with enabled js
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS)
不确定,但只有在使用java版本时,AFAIK HtmlUnitDriver才可用 webdriver的开发。如果要在python中使用htmlunit驱动程序,需要启动独立服务器
java -jar selenium-server-standalone-x.x.x.jar
然后通过远程服务器连接到使用
from selenium import webdriver
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT)
//or with enabled js
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS)
可能的重复可能的重复