var pages = ['http://2ch.hk/s/res/1358828.html', 'http://2ch.hk/s/res/1354275.html'],
imgSelector = 'div.image-link > a',
sourceAttr = 'href';
var cheerio = require('cheerio'),
http = require('http');
var hostname;
pages.forEach(function (url) {
http.get(url, readPage);
hostname = require('url').parse(url).hostname;
});
function readPage (res) {
var page = '';
res.on('data', function (chunk) {
page += chunk;
});
res.on('end', function () {
getImage(page);
});
}
function getImage (page) {
var $ = cheerio.load(page);
$(imgSelector).each(function () {
console.log(hostname + $(this).attr(sourceAttr));
});
}