Created
May 16, 2013 07:51
-
-
Save niceaji/5590106 to your computer and use it in GitHub Desktop.
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 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