如何使用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();
});
解决方案

尝试负载您使用jQuery页面:

page.includeJs(http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js”功能(){
    //(...)
});

然后调用悬停你的元素:

$('#some_element')触发('悬停');

本文地址:IT屋 » 如何使用phantomJS来模拟一个HTML元素的鼠标悬停


通过CDN引入jQuery的几种方式

 
微信公众号搜索 “ IT屋 ” ,选择关注

最新文章

  1. CodeSmith模板代码生成实战详解
  2. 一步一步搭框架(asp.netmvc+easyui+sqlserver)-01
  3. 背景建模post_processing常用opencv函数(怒了)
  4. 查看oracle被锁的表
  5. js之oop <二> 对象属性
  6. 最常用的DOS命令
  7. .NET单元测试
  8. 最初步的正则表达式引擎:nfa的转换规则。
  9. python 技巧 之 pyCharm快速添加第三方库和插件
  10. javascript属性一览
  11. BIEE在creating domain步骤停止的解决的方法
  12. 离开Visual Studio C#的编译(你不知道的C#)
  13. Newtonsoft.Json 版本冲突时解决方案
  14. vue性能
  15. 如何取消Paypal自动付款功能
  16. [LeetCode] Reaching Points 到达指定点
  17. iptables 配置说明
  18. 在Ubuntu上更新Chrome到最新的版本
  19. Python时钟,计算程序运行时间
  20. MapReduce案例:统计共同好友+订单表多表合并+求每个订单中最贵的商品

热门文章

  1. oracle 排序后分页查询
  2. Jmeter CSV参数带汉字处理
  3. windows中的出站和入站规则
  4. 分页查询——Hibernate Criteria实现一次查询取得总记录数和分页后结果集
  5. idea操作maven时控制台中文显示乱码/maven项目启动方式
  6. Web服务基础介绍
  7. C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法
  8. Android开发学习了这些,上帝都淘汰不了你
  9. pandas的行列显示不全的解决方法
  10. 2019年牛客多校第二场 F题Partition problem 爆搜