Created
January 30, 2017 19:46
-
-
Save adityashedge/8b43c129d4d4ca1d94b04b0bf9f3b64e to your computer and use it in GitHub Desktop.
JS crawler to get description and NPM package for all the 'nodeschool' workshops.
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
/* | |
"dependencies": { | |
"cheerio": "^0.22.0", | |
"request": "^2.79.0" | |
} | |
*/ | |
const request = require('request'); | |
const cheerio = require('cheerio'); | |
const SITE_URL = 'https://nodeschool.io'; | |
const SEPARATOR = '-'.repeat(100); | |
function Crawler(url) { | |
this.url = url; | |
this.start = function() { | |
request(this.url, function(error, response, body) { | |
if(error) { | |
console.log('Error:', error.message); | |
return; | |
} | |
const $ = cheerio.load(body); | |
const elements = $('.workshopper'); | |
for(var i = 0; i < elements.length; i++) { | |
$ele = $(elements[i]); | |
if($ele.attr('id')){ | |
var npmCodes = $ele.find('code'); | |
for(var j = 0; j < npmCodes.length; j++) { | |
$npmCode = $(npmCodes[j]); | |
if($npmCode.parent().hasClass('workshopper')) { | |
console.log(SEPARATOR); | |
console.log($ele.find('p').text()); | |
console.log($npmCode.text()); | |
} | |
} | |
} | |
} | |
}); | |
} | |
} | |
crawler = new Crawler(SITE_URL); | |
crawler.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment