Skip to content

Instantly share code, notes, and snippets.

@j8
Created September 9, 2015 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j8/3c198c09191d15036eb4 to your computer and use it in GitHub Desktop.
Save j8/3c198c09191d15036eb4 to your computer and use it in GitHub Desktop.
nic.io scrapping script
var express = require('express');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
// Params
var min = 6000;
var max = 10000;
var wordCount = 0;
function getRandomInt(min, max) {
var random = Math.floor(Math.random() * (max - min + 1)) + min;
return random;
}
app.get('/scrape', function(req, res){
var LineByLineReader = require('line-by-line');
var lr = new LineByLineReader('list_of_words.txt');
// Read words file
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
}
lr.on('error', function (err) {
console.log("erorr", err);
});
lr.on('line', function (word) {
lr.pause();
wordCount += 1;
var word = word;
setTimeout(function () {
request({url: 'http://nic.io/cgi-bin/whois',method: 'GET', headers: headers, qs: {'query': word + '.io'}, timeout: 10000}, function(error, response, html){
if(!error && response.statusCode == 200){
var $ = cheerio.load(html);
console.log("Checking word....< ", word, " >. Word count: ", wordCount);
$("#bodyfill b").filter(function() {
if( $(this).text().indexOf('pendingDelete') >= 0) {
console.log(" ---> YAY!!!!! ###FREE ", $(this).text(), " for word: " + word);
lr.resume();
} else if ( $(this).text().indexOf('This Domain is') >= 0) {
console.log(" ---> Domain free!!!!!", "for word: " + word);
lr.resume();
} else {
lr.resume();
}
});
} else {
console.log("I got error or timeout");
lr.resume();
}
});
}, getRandomInt(min,max));
});
lr.on('end', function () {
console.log("!!!!!!!!!!!!!!!!!!! Done !!!!!!!!!!!!!!!!!!!");
});
res.send('Check your console!')
})
app.listen('8081')
console.log('Magic happens on port 8081');
exports = module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment