Created
September 19, 2014 21:48
-
-
Save connyay/879b6aa2abdb7afa8f8f to your computer and use it in GitHub Desktop.
zombie example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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