Last active
May 13, 2016 21:33
-
-
Save goodbabies/716925a4f96b170599a1756c5b3a4ce9 to your computer and use it in GitHub Desktop.
This file contains 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 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