Skip to content

Instantly share code, notes, and snippets.

@connyay
Created September 19, 2014 21:48
Show Gist options
  • Save connyay/879b6aa2abdb7afa8f8f to your computer and use it in GitHub Desktop.
Save connyay/879b6aa2abdb7afa8f8f to your computer and use it in GitHub Desktop.
zombie example
'use strict';
var Browser = require('zombie');
function logResult(num, period) {
console.log('There were ' + parseInt(num.replace(' ', ''), 10) + ' downloads in the last ' + period);
}
Browser.visit('https://www.npmjs.org/package/zombie', function(e, browser) {
var lastDay = browser.querySelector('.downloads tr:nth-of-type(1) td'),
lastWeek = browser.querySelector('.downloads tr:nth-of-type(2) td'),
lastMonth = browser.querySelector('.downloads tr:nth-of-type(3) td');
console.log('Results for package ' + browser.querySelector('#package h1').textContent);
if (lastDay) {
logResult(lastDay.textContent, 'day');
}
if (lastWeek) {
logResult(lastWeek.textContent, 'week');
}
if (lastMonth) {
logResult(lastMonth.textContent, 'month');
}
});
{
"name": "zombieexample",
"version": "0.0.0",
"description": "",
"main": "index.js",
"author": "Connor Hindley <conn.hindley@gmail.com> (http://connorhindley.com/)",
"license": "MIT",
"dependencies": {
"zombie": "~2.0.0-alpha31"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment