zombie-phantom
zombie-phantom Provides a Zombie.js shim around the PhantomJS Headless Browser. npm install zombie-phantom 3 downloads in the last day 8 downloads in the last week 31 downloads in the last month Maintainers travist Version 0.0.6 last updated 9 months ago Repository git://github.com/travist/zombie-phantom.git (git) Homepage http://github.com/travist/zombie-phantom Bugs http://github.com/travist/zombie-phantom/issues Dependencies node-phantom, underscore, async Dependents drupalgo Read Me Zombie Phantom This is a Node.js package that provides a Zombie.js shim around the PhantomJS headless browser. The motivation behind this package is that when looking for a headless browser solution, I really liked the API of Zombie.js as well as the full Node.js support behind it, however it is not a full WebKit browser. PhantomJS on the other hand is a better technology in terms of headless browser, but does not have a native Node.js integration. The Node Phantom package integrates the PhantomJS into the Node.js framework, but what it doesn't do, and likely so, is provide a better API like the Zombie.js framework. This package simply attempts to act as a drop-in replacement for Zombie.js but using the PhantomJS headless browser. NOTE: THIS PACKAGE IS STILL INCOMPLETE AND IS NOT A FULL DROP-IN REPLACEMENT FOR ZOMBIE.JS Installation Step 1 Install node.js by going to http://nodejs.org Step 2 Install PhantomJS by going to http://phantomjs.org/download.html Step 3 Install this package using Node Package Manager (npm) npm install zombie-phantom Differences between Zombie.js Using this library is going to be 'similar' to using Zombie.js. I couldn't make it an exact replica of Zombie.js due to the nature of the asynchronous behavior of interacting with any API within PhantomJS. For example, to get the text of an element on the page looks like the following in both Zombie.js and this module. Zombie.js var Browser = require('zombie'); var browser = new Browser({ site: 'http://localhost:8888' }); browser.visit('/user/login', function() { var text = browser.text('h1'); console.log(text); }); Whereas in Zombie-Phantom, everything is asynchronous... like so. Zombie-Phantom var Browser = require('zombie'); var browser = new Browser({ site: 'http://localhost:8888' }); browser.visit('/user/login', function() { browser.text('h1', function(text) { console.log(text); }); }); Using query, queryAll, and xpath Another big difference is that this library does not return actual DOM elements which you can use to manipulate. It does however, return an index into a DOM array within the PhantomJS browser which you can use to perform the same actions as you would with Zombie.js. It is easier to think of this index as a DOM element ID which you return back to the library to do stuff... Here is an example. var _ = require('underscore'); var async = require('async'); var Browser = require('zombie'); var browser = new Browser({ site: 'http://localhost:8888' }); browser.visit('/user/login', function() { browser.query('h1.title', function(title) { // title is actually an ID to a DOM element here, not an actual element. // But, I can still pass it along to the browser API like I would and it // will still work by referencing the DOM element within PhantomJS. browser.xpath('..//label', title, function(labels) { // labels is actually just an array of ID's here, but I can still use them _.each(labels, function(label) { drupal.browser.text(label, function(text) { console.log(text); }); }); }); }); }); Promises using Async.js As you can tell, the promise system from Zombie.js has not been implemented, however, you can replicate this functionality using the Async.js library. Here is an example of using the promises from async to turn what was once callback hell into an easy to follow series of executions. example.js var Browser = require('zombie-phantom'); var async = require('async'); var browser = new Browser({ site: 'http://localhost:8888' }); // Current this library does not support promises, but you can use async.series // to get something similar... async.series([ function(done) { browser.visit('/user/login', done); }, function(done) { browser.fill('#user-name', 'admin', done); }, function(done) { browser.fill('#user-pass', '123password', done); }, function(done) { browser.pressButton('#edit-submit', done); }, function(done) { browser.visit('/node/add/article', done); }, function(done) { browser.fill('#edit-title', 'This is a test!', done); }, function(done) { browser.pressButton('#edit-submit', done) } ], function() { console.log('Content Created!'); browser.close(); }); Please contribute to make this project better.
zombie-phantom的更多相关文章
- 避免产生僵尸进程的N种方法(zombie process)
http://blog.csdn.net/duyiwuer2009/article/details/7964795 认识僵尸进程 1.如果父进程先退出 子进程自动被 init 进程收养,不会产生僵尸进 ...
- 强(strong)、软(soft)、弱(weak)、虚(phantom)引用
https://github.com/Androooid/treasure/blob/master/source/lightsky/posts/mat_usage.md 1.1 GC Root JAV ...
- OC内存管理--zombie对象
当我们对于内存进行手动管理的时候,会出现两种错误:一种是野指针错误,一种则为内存泄露.这两点也是我们去管理内存时最终要解决的问题. 内存泄漏是指:不在使用的对象,一直保留在内存中未被销毁,一直占有着内 ...
- Phantom omini设备开发流程
最近在忙着做毕业设计,我的毕业设计是做力觉临场感的,所以在力反馈设备Phantom Omini,由于整个设备是国外的国内的资料很少,我是14年拿到这个设备的但是真的是在开发是在16年了,中间有很多事没 ...
- HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)
Problem Description Do you know Kaitou Kid? In the legend, Kaitou Kid is a master of disguise, and c ...
- 14.5.4 Phantom Rows 幻影行
14.5.4 Phantom Rows 幻影行 所谓的幻读问题发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 例如,如果一个SELECT 是执行2次,但是第2次返回的时间不第一次返回不同, ...
- bom type:Phantom
bom的类型 'type': fields.selection([('normal','Normal BoM'),('phantom','Sets / Phantom')], 'BoM Type', ...
- Hdu3640-I, zombie(模拟+二分)
The "endless" model in "I, zombie" of "Plants vs. Zombies" is my favou ...
- How to choose between zombie.js and PhantomJS for automated web testing? [closed]
How to choose between zombie.js and PhantomJS for automated web testing? [closed] How to choose betw ...
随机推荐
- Docker的C/S模式详解
Docker的C/S模式 Docker的C/S模式 Docker Client通过Remote API与Docker Server通信: RESTful风格API STDIN.STDOUT.STDER ...
- javascript 多行字符串
javascript 字符串多行 平时一般使用 字符串+,或者[].join('')的方式 同事推荐了这样的形式 ExceptionDivHtml="<div class='gameI ...
- hdu 2604Queuing dp+ 矩阵快速幂
题目链接 给一个长度为n的字符串, 每个字符可以使f或m. 问你不包含子串fmf以及fff的字符串数量有多少. 令0表示mm结尾, 1表示mf, 2表示ff, 3表示fm. 那么 f(n+1, 0) ...
- OpenGL绘制环形渐变
开始看计算机图形学和OpenGL,挺有意思就自己随便写了一些效果. 以中间点坐标为圆心,计算每一点和圆心距离,根据距离算出一个RGB值,于是整体便呈现环形分布. 代码如下: #include < ...
- 程序员眼里IE浏览器是什么样的
主流浏览器之争从上个世纪开就开始,已经持续了很长的时间.就在几年前,IE还是最主流的web浏览器.但现在形势完全不同了,人们都在笑话IE,纷纷转向其它浏览器.今天,我向大家分享一下针对IE的搞笑图片, ...
- Qt 的线程与事件循环——可打印threadid进行观察槽函数到底是在哪个线程里执行,学习moveToThread的使用)
周末天冷,索性把电脑抱到床上上网,这几天看了 dbzhang800 博客关于 Qt 事件循环的几篇 Blog,发现自己对 Qt 的事件循环有不少误解.从来只看到现象,这次借 dbzhang800 的博 ...
- 【CTSC1999】【解救大兵瑞恩】
44. [CTSC1999] 解救大兵瑞恩 ★★☆ 输入文件:rescue.in 输出文件:rescue.out 简单对照 时间限制:1 s 内存限制:128 MB 问题描写叙述 1944年,特种兵麦 ...
- CouchDB简单应用
CouchDB是众多称作NoSQL解决方案中的一员.与众不同的是,CouchDB是一个面向文档的数据库,在它里面所有文档域(Field)都是以键值对的形式存储的.域(Field)可以是一个简单的键值对 ...
- 腾讯TGideas语义化标签(转)
--------引子--------------- 家里有个熊孩子,经常会有一些意想不到的事情发生:回家的时候,他会笑呵呵冲过来,大声喊着“臭爸爸”:你让他把鞋穿上,他会提起鞋子往楼下扔...在小孩的 ...
- 设计模式之---模板方法template method的使用
在面向对象系统的分析与设计过程中经常会遇到这样一种情况:对于某一个业务逻辑(算法实现)在不同的对象中有不同的细节实现,但是逻辑(算法)的框架(或通用的应用算法)是相同的.Template Method ...