selenium使用更快的Driver-HtmlUnit Driver
转自:http://sunjun041640.blog.163.com/blog/static/2562683220131024114610625/
selenium使用更快的Driver--HtmlUnit Driver
2013-11-24 12:05:20| 分类: Java | 标签:selenium |举报|字号 订阅
HtmlUnit Driver
This is currently the fastest and most lightweight implementation of WebDriver. As the name suggests, this is based on HtmlUnit. HtmlUnit is a java based implementation of a WebBrowser without a GUI. For any language binding (other than java) the Selenium Server is required to use this driver.
这个driver是当前最快的driver实现
Usage
WebDriver driver = new HtmlUnitDriver(); //java的使用方式
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT) //python的使用方式
Pros
- Fastest implementation of WebDriver//最快的
- A pure Java solution and so it is platform independent.//纯java实现,所以是跨平台的
- Supports JavaScript//支持js
Cons
- Emulates other browsers’ JavaScript behaviour (see below)
JavaScript in the HtmlUnit Driver //如何开启javascript的支持
None of the popular browsers uses the JavaScript engine used by HtmlUnit (Rhino). If you test JavaScript using HtmlUnit the results may differ significantly from those browsers.
When we say “JavaScript” we actually mean “JavaScript and the DOM”. Although the DOM is defined by the W3C each browser has its own quirks and differences in their implementation of the DOM and in how JavaScript interacts with it. HtmlUnit has an impressively complete implementation of the DOM and has good support for using JavaScript, but it is no different from any other browser: it has its own quirks and differences from both the W3C standard and the DOM implementations of the major browsers, despite its ability to mimic other browsers.
With WebDriver, we had to make a choice; do we enable HtmlUnit’s JavaScript capabilities and run the risk of teams running into problems that only manifest themselves there, or do we leave JavaScript disabled, knowing that there are more and more sites that rely on JavaScript? We took the conservative approach, and by default have disabled support when we use HtmlUnit. With each release of both WebDriver and HtmlUnit, we reassess this decision: we hope to enable JavaScript by default on the HtmlUnit at some point.
Enabling JavaScript
If you can’t wait, enabling JavaScript support is very easy:
HtmlUnitDriver driver = new HtmlUnitDriver(true); //java的调用方式
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS) //python的调用方式
This will cause the HtmlUnit Driver to emulate Firefox 3.6’s JavaScript handling by default.
//上述代码会使得 HtmlUnit Driver 模拟 Firefox3.6 对 JavaScript 的处理。
java:
WebDriver driver =newRemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
DesiredCapabilities.htmlUnitWithJs());
python:
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS)
相关推荐
- JS网页信息的提取2(selenium的使用)
- 使用selenium和chromedriver组合爬虫时,如果爬取的页面数量巨多,会出现占用内存逐渐增大知道程序崩溃的情况
- selenium的简单使用
- selenium的基本使用
- selenium使用遇到的问题(selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.)
- selenium和PhantomJS的使用
- webdriverAPI-Java 第2章 Webdirver对浏览器的支持 第3章 使用操作 第4章 RemoteWebDriver 第5章 封装与重用 第6章 在selenium2.0中使用selenium1.0的API
- 使用 mitmdump 进行 selenium webDriver绕过网站反爬服务的方法 pdd某宝 可用
- 收藏的一些文章 1 . 使用python+selenium控制手工已打开的浏览器 2 . 协程(Coroutine)
- DDD(Domain Driver Designer) 领域驱动设计简介 DDD(Domain Driver Designer) 领域驱动设计简介 领域驱动设计之领域模型 为什么建立一个领域模型是重要的 领域通用语言(UBIQUITOUS LANGUAGE) 将领域模型转换为代码实现的最佳实践 领域建模时思考问题的角度 领域驱动设计的经典分层架构 领域驱动设计过程中使用的模式 设计领域模型的一般步骤 在分层架构中其他层如何与领域层交互 为什么面向对象比面向过程更能适应业务变化 领域驱动设计的其他一些主题 一些相关的扩展阅读
- json拼接的字符串,日期格式转换有关问题
- HtmlUnit抓取js点染页面