Created
May 9, 2014 22:01
-
-
Save thibauts/2c897eb4c97b3d190f1a to your computer and use it in GitHub Desktop.
Extract links from a webpage with concat-stream
This file contains hidden or 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 concat = require('concat-stream'); | |
http.get(process.argv[2], function(res) { | |
res.pipe(concat(function(buf) { | |
var html = buf.toString(); | |
var re = /<a.*?href="(.*?)".*?>/gi; | |
var links = []; | |
var matches; | |
while(matches = re.exec(html)) { | |
links.push(matches[1]); | |
}; | |
console.log(links); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment