Skip to content

Instantly share code, notes, and snippets.

@niceaji
Created May 16, 2013 07:51
Show Gist options
  • Save niceaji/5590106 to your computer and use it in GitHub Desktop.
Save niceaji/5590106 to your computer and use it in GitHub Desktop.
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var step =require('step');
step(
function readUrl(){
console.log("readUrl")
request('http://www.daum.net', this);
},
function parseImg(err, data){
console.log("parseImg")
var $ = cheerio.load(data.body);
var imgUrl = [];
$('img').each(function(index, el){
imgUrl.push($(el).attr('src'))
// console.log( );
});
return imgUrl;
},
function makeFile(err, imgUrl){
console.log("makeFile")
fs.writeFile('daum-imgurl.txt', imgUrl, this);
},
function done(err, data){
console.log('It\'s saved!');
}
);
return;
request('http://www.daum.net', function (error, response, body) {
if (!error && response.statusCode == 200) {
// console.log(body);
var $ = cheerio.load(body);
var imgUrl = [];
$('img').each(function(index, el){
imgUrl.push($(el).attr('src'))
// console.log( );
});
fs.writeFile('daum-imgurl.txt', imgUrl, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment