Created
June 22, 2012 09:23
-
-
Save athoune/2971618 to your computer and use it in GitHub Desktop.
test page content in a loop
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
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