| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

Phantomjs的高度封装:nightmare

nightmare是PhantomJS的高级封装,让你能够实现浏览器自动化任务。PhantomJS 是一个基于WebKit的服务器端 JavaScript API。它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, JSON, Canvas, 和 SVG。PhantomJS可以用于页面自动化,网络监测,网页截屏,以及无界面测试等。

示例

实现在Yahoo上搜索:

var Nightmare = require('nightmare');  new Nightmare()    .goto('http://yahoo.com')      .type('input[title="Search"]', 'github nightmare')      .click('.searchsubmit')      .run(function (err, nightmare) {        if (err) return console.log(err);        console.log('Done!');      });

Or, let's extract the entirety of Kayak's home page after everything has rendered:

var Nightmare = require('nightmare');  new Nightmare()    .goto('http://kayak.com')    .evaluate(function (page) {      return document.documentElement.innerHTML;    }, function (res) {      console.log(res);    })    .run();

Or, here's how you might automate a nicely abstracted login + task on Swiftly:

var Nightmare = require('nightmare');  var Swiftly = require('nightmare-swiftly');  new Nightmare()    .use(Swiftly.login(email, password))    .use(Swiftly.task(instructions, uploads, path))    .run(function(err, nightmare){      if (err) return fn(err);      fn();    });

项目主页:http://www.open-open.com/lib/view/home/1412738918764

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1412738918764.html
nightmare JavaScript开发