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. Docker镜像与仓库(一)

    Docker镜像与仓库(一) Docker镜像与仓库(一) 如何查找镜像? Docker Hub https://registry.hub.docker.com docker search [OPTI ...

  2. @RenderSection

    @RenderSection在母版页中先占个位置,然后在使用该母版的页面中在各自去实现自己的Section. 在母版页_Layout.cshtml中使用格式为 @RenderSection(" ...

  3. Xampp Linux应用

    一.基本操作: 1.Xampp安装包下载:   https://www.apachefriends.org/index.html   2.安装与配置:   将xampp-linux-x64-5.6.3 ...

  4. Oracle EBS-SQL (SYS-22):sysadmin_用户职责查询.sql

    select fu.user_name 用户名, fu.description 用户说明, frv.RESPONSIBILITY_NAME 职责名称, REQUEST_GROUP_NAME 报表组, ...

  5. 文件转换dll mingw

    MinGW:c -> o           gcc -c a.cc -> exe         gcc a.c libs.o -o a.exe (从主程序a.c,附加libs,生成a. ...

  6. 一个大小为N的数组,里面是N个整数,怎样去除重复的数

    题目:一个大小为N的数组,里面是N个整数,怎样去除重复的数字: 要求时间复杂度为O(n),空间复杂度为O(1). 需要除掉重复的整数的数组,注意这里我没有处理负数情况,其实负数情况只要先用0快排分一下 ...

  7. c#搭建服务端 简单中最高效的数据操作Linq (4)

    .NET F 3.5之后提出的linq to sql 概念,大大的简化了对于数据对象的操作,可以通过简单的语法直接操作数据对象,如List,Linq to sql类 等等. 1.使用Linq to s ...

  8. Mongodb数据库命令端经常使用操作

    数据库基本命令操作 数据库经常使用命令 1.Help查看命令提示 help db.help(); db.yourColl.help(); db.youColl.find().help(); rs.he ...

  9. 在centos6.5下yum仓库的创建

    第一步:打开虚拟机,装入光盘镜像,选择为已连接 第二步: df -h mount umount /dev/sr0 mkdir /centos mount /dev/sr0 /centos mkdir ...

  10. English - according to 的用法说明

    1. 用于according to,意为“根据”,为复合介词,后接名词或代词.注意以下用法: (1) 主要用来表示“根据”某学说.某书刊.某文件.某人所说等或表示“按照”某法律.某规定.某惯例.某情况 ...