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 ...
随机推荐
- 《转》读discuzx3.1 数据库层笔记
最近开始在看discuzx3.1的代码,看到数据库层的实现,discuzx的数据库层能够支撑数据库分库,分布式部署,主要水平分表,也可以很方便的支持其他数据库.性能上,可以做读写分离,支持数据缓存.可 ...
- XP下Virtualbox虚拟Ubuntu共享文件夹设置
环境:主机操作系统是Windows XP,虚拟机是Ubuntu 8.10,虚拟机是VirtualBox 2.1.0. 1. 安装增强功能包(Guest Additions) 安装好Ubuntu 8.1 ...
- linux安装php遇到的问题
第一个问题:configure: error: libjpeg.(a|so) not found 很多人都纳闷儿了,我都安装了的,为什么就找不到呢?找不到其实就应试想到它的搜索位置里面是没有的,要不然 ...
- Labeling Balls(拓扑排序wa)
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12466 Accepted: 3576 D ...
- 神奇的i=i++
最近在看c语言,被神奇的i=i++吸引,其实感觉编程是一件有趣的事情(特别喜欢算法).下面是我的测试,linux 下 gcc编译 #include<stdio.h> main () { ...
- 值得赞扬的尝试与进步——CSDN开源夏令营第一印象
注:写这篇文章时我并未參加CSDN开源夏令营,也不确定是否会參加以及是否能參加上. 欣闻CSDN举办了"CSDN开源夏令营"活动.第一感觉是CSDN作为活动的组织者是很值得称赞的. ...
- 音乐ID3 中 专辑封面解析(APIC帧)
ID3V2 中 APIC 帧标识 专辑封面.前几天 百度 谷歌 都没有找到具体的说明.有点小伤人. 最好参考 Android 中的 id3.cpp 以及一个java 开源 id3 库.找到这里的规格 ...
- JavaScript之arguements对象学习
简介:在JavaScript中,有一个特殊的对象-Arguements对象,它是当前函数的一个内置属性,它类似与Array对象(数组形式),但不是Array的一个实例.下面通过代码来论证: <s ...
- 指定hive输出格式
0.11版本以前: sed -e 's/\x01/|/g' file 0.11版本以后: insert overwrite local directory '/opt/aimcpro/libc/tes ...
- Android 创建目录
//android 内部存储自定义目录写入文件 try{ File testDir = new File(this.getFilesDir().getAbsolutePath() + File.sep ...