如何使用phantomJS来模拟一个HTML元素的鼠标悬停
如何使用phantomJS来模拟一个HTML元素的鼠标悬停
(How to use phantomJS to simulate mouse hover on a HTML element)
I have the phantomJS code below to fetch the HTML code:
var page = require('webpage').create();
var url = 'http://www.abc.com/'; page.open(url, function (status) {
var js = page.evaluate(function () {
return document;
});
console.log(js.all[0].outerHTML);
phantom.exit();
});
The content I want to fetch will only be read while the mouse is hover on the specific element which is controlled by JavaScript, so the code above is not working.
I want to know how to simulate the mouse hover on a HTML element using the phantomJS code. Let's say I want to mouse hover over on a element then dump the HTML to output, how should I do?
Edit: The following code didn't work. What could be the problem?
var page = require('webpage').create();
var url = 'http://www.abc.com/'; page.open(url, function (status) {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function(){
$('#some_element').trigger('hover');
});
var js = page.evaluate(function () {
return document;
});
console.log(js.all[0].outerHTML);
phantom.exit();
});
Try load your page with jquery:
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
//(...)
});
and then call hover on your element:
$('#some_element').trigger('hover');
本文地址:IT屋 » How to use phantomJS to simulate mouse hover on a HTML element
我有以下phantomJS code,以获取HTML code:
VAR页=要求('网页')创建()。
VAR URL ='http://www.abc.com/'; page.open(URL,功能(状态){
VAR JS = page.evaluate(函数(){
返回文件;
});
的console.log(js.all [0] .outerHTML);
phantom.exit();
});
我想取将只读取当鼠标悬停是由JavaScript控制的特定元素上的内容,所以上面的code是行不通的。
我想知道如何模拟使用phantomJS code一个HTML元素的鼠标悬停。比方说,我想鼠标悬停在某个元素上,然后倾倒HTML输出,我应该怎么办?
编辑:下面code没有工作。可能是什么问题?
VAR页=要求('网页')创建()。
VAR URL ='http://www.abc.com/';page.open(URL,功能(状态){
page.includeJs(http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js”功能(){
$('#some_element')触发('悬停')。
});
VAR JS = page.evaluate(函数(){
返回文件;
});
的console.log(js.all [0] .outerHTML);
phantom.exit();
});
page.includeJs(http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js”功能(){
//(...)
});
$('#some_element')触发('悬停');
本文地址:IT屋 » 如何使用phantomJS来模拟一个HTML元素的鼠标悬停
最新文章
- CodeSmith模板代码生成实战详解
- 一步一步搭框架(asp.netmvc+easyui+sqlserver)-01
- 背景建模post_processing常用opencv函数(怒了)
- 查看oracle被锁的表
- js之oop <;二>; 对象属性
- 最常用的DOS命令
- .NET单元测试
- 最初步的正则表达式引擎:nfa的转换规则。
- python 技巧 之 pyCharm快速添加第三方库和插件
- javascript属性一览
- BIEE在creating domain步骤停止的解决的方法
- 离开Visual Studio C#的编译(你不知道的C#)
- Newtonsoft.Json 版本冲突时解决方案
- vue性能
- 如何取消Paypal自动付款功能
- [LeetCode] Reaching Points 到达指定点
- iptables 配置说明
- 在Ubuntu上更新Chrome到最新的版本
- Python时钟,计算程序运行时间
- MapReduce案例:统计共同好友+订单表多表合并+求每个订单中最贵的商品