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的更多相关文章

  1. 避免产生僵尸进程的N种方法(zombie process)

    http://blog.csdn.net/duyiwuer2009/article/details/7964795 认识僵尸进程 1.如果父进程先退出 子进程自动被 init 进程收养,不会产生僵尸进 ...

  2. 强(strong)、软(soft)、弱(weak)、虚(phantom)引用

    https://github.com/Androooid/treasure/blob/master/source/lightsky/posts/mat_usage.md 1.1 GC Root JAV ...

  3. OC内存管理--zombie对象

    当我们对于内存进行手动管理的时候,会出现两种错误:一种是野指针错误,一种则为内存泄露.这两点也是我们去管理内存时最终要解决的问题. 内存泄漏是指:不在使用的对象,一直保留在内存中未被销毁,一直占有着内 ...

  4. Phantom omini设备开发流程

    最近在忙着做毕业设计,我的毕业设计是做力觉临场感的,所以在力反馈设备Phantom Omini,由于整个设备是国外的国内的资料很少,我是14年拿到这个设备的但是真的是在开发是在16年了,中间有很多事没 ...

  5. 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 ...

  6. 14.5.4 Phantom Rows 幻影行

    14.5.4 Phantom Rows 幻影行 所谓的幻读问题发生在一个事务 当相同的查询产生不同的结果集在不同的时间. 例如,如果一个SELECT 是执行2次,但是第2次返回的时间不第一次返回不同, ...

  7. bom type:Phantom

    bom的类型 'type': fields.selection([('normal','Normal BoM'),('phantom','Sets / Phantom')], 'BoM Type', ...

  8. Hdu3640-I, zombie(模拟+二分)

    The "endless" model in "I, zombie" of "Plants vs. Zombies" is my favou ...

  9. 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 ...

随机推荐

  1. C#两路list数组归并去重

    两个相同类型已排序数据进行合并,虽然list数组中有AddRange方法,但它只是把第二个数组从第一个数组末尾插入,假如两个数组有重复数据,保存进去.还有Union方法合并去重,首先会从第一个数组进行 ...

  2. composer时间长了,提示需要升级,结果问题来了

    今天重新开始之前的laravel项目,结果composer提示需要升级,于是 composer selfupdate 结果提示无法连接目标库,查阅composer官网,发现之前的库地址已经启用了ssl ...

  3. 手把手教程 Surface如何进行系统恢复?

    手把手教程 Surface如何进行系统恢复? 2015-01-29 05:53:00  [  中关村在线 原创  ]   作者: 周博林 |  责编:周博林 收藏文章 分享到 评论(10) Windo ...

  4. WPF:构建应用程序

    原文 http://www.cnblogs.com/free722/archive/2011/11/13/2247455.html WPF相关的项目内容包含在App.Xaml和Window1.xaml ...

  5. Cppcheck软件使用

    一款开源源码检测工具.简单易用. 官网网址:http://cppcheck.sourceforge.net/ 软件可直接官网下载. [plain] view plaincopy Features Ou ...

  6. C++中的句柄类

    初次在<C++ Primer>看到句柄,不是特别理解.在搜索相关资料后,终于有了点头绪. 首先明白句柄要解决什么问题.参考文章<C++ 沉思录>阅读笔记——代理类 场景: 我们 ...

  7. 最终有SpringMvc与Struts2的对照啦

    眼下企业中使用SpringMvc的比例已经远远超过Struts2,那么两者究竟有什么差别,是非常多刚開始学习的人比較关注的问题,以下我们就来对SpringMvc和Struts2进行各方面的比較: 1. ...

  8. 转载:做Java开发这一年 (火龙果软件)

    转载:http://www.uml.org.cn/success/201410205.asp 从去年到现在,从.NET转向Java开发(只是因为项目原因,绝对与平台好坏没有关系)差不多有一年的时间了. ...

  9. AngularJs(一) MVC 模式的应用

    Model的应用 MVC的模式大家都是十分熟悉了,那么Angular是怎么规划的呢.数据被放在json文件中,通过Ajax获取数据. [{ "action": "Buy ...

  10. css3 动画(animation)-简单入门

    css3之动画(animation) css3中我们可以使用动画,由于取代以前的gif图片,flash动画,以及部分javascript代码(相信有很多同学都用过jquery中的animate方法来做 ...