Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save goodbabies/716925a4f96b170599a1756c5b3a4ce9 to your computer and use it in GitHub Desktop.
Save goodbabies/716925a4f96b170599a1756c5b3a4ce9 to your computer and use it in GitHub Desktop.
var client = require('cheerio-httpcli');
var request = require('request');
var fs = require('fs');
var URL = require('url');
var Dir = "./files/img";
if (!fs.existsSync(Dir)) {
fs.mkdirSync(Dir);
}
var url = "http://www.pet-home.jp/cats/";
var param = {};
client.fetch(url, param, function(err, $, res) {
if (err) { console.log("error"); return; }
$(".contribute_result .img_container:first-child img").each(function(i) {
var src = $(this).attr('src');
src = URL.resolve(url, src);
var file_name = URL.parse(src).pathname;
file_name = Dir + "/" + file_name.replace(/[^a-zA-Z0-9\.]+/g, '-');
request(src).pipe(fs.createWriteStream(file_name));//ダウンロードファイル書き込み
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment