Skip to content

Instantly share code, notes, and snippets.

@song940
Last active February 8, 2017 02:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save song940/a019a45a703914adea305f6f93922807 to your computer and use it in GitHub Desktop.
Save song940/a019a45a703914adea305f6f93922807 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
//
// ~$ yarn add superagent cheerio
// ~$ ./iguooo.js > gifs.list
// ~$ cat iguooo.list | awk '{ print $1 }' | wget -Nci -
//
const cheerio = require('cheerio');
const request = require('superagent');
const regexp = /background-image:\s?url\([\'"]?(.[^\'"]+)[\'"]?\)/;
var list = [], count = 0;
(function loop(){
// 1. http://iguooo.com/gif_1000?s=100000
// 2. http://www.wulangdashu.com/pic_100
request.get('http://www.wulangdashu.com/pic_100', function(err, res){
var $ = cheerio.load(res.text);
$('.item a.slide').each(function(i, slide){
slide = $(slide);
var item = slide.closest('.item');
var img = regexp.exec(slide.attr('style'))[1];
var desc = $('.desc-w > p', item).text();
if(!~list.indexOf(img)) {
list.push(img);
console.log(img, desc);
}
});
if(list.length > count){
count = list.length;
loop();
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment