Quick actions

cmd+k|ctrl+k

Navigation

Languages

на ноде за пять минут

Snippet info

Language

JavaScript

Visibility

public

Author

karaseeque

Created

2015-08-20T13:16:07Z

Updated

2015-08-20T13:22:18Z

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));
	});
}
INFO