-
-
Save esironal/82c8d517af53adac6091e7dea7181d22 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