Skip to content

Instantly share code, notes, and snippets.

@athoune
Created June 22, 2012 09:23
Show Gist options
  • Save athoune/2971618 to your computer and use it in GitHub Desktop.
Save athoune/2971618 to your computer and use it in GitHub Desktop.
test page content in a loop
var http = require('http');
var options = {
host: 'ze.garambrogne.net',
port: 80,
path: '/'
};
var cpt = 0;
var good = 0;
var SIZE = 500;
var pattern = /popo/;
for(var i=0; i < SIZE; i++) {
http.get(options, function(res) {
cpt += 1;
if (res.statusCode == 200) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
if (pattern.test(data)) {
good += 1;
}
});
}
if (cpt == SIZE) {
console.log("done", good);
}
}).on('error', function(e) {
console.log(e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment