-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyin.js
33 lines (30 loc) · 990 Bytes
/
yin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const request = require('request');
const fs = require('fs');
(() => {
const yinUrl = 'https://yys.tongren.163.com/article/?sort=new&span=30&tags=Cosplay&tags=%E5%90%8C%E4%BA%BACOS&start=180';
getUrl(yinUrl);
})();
function getUrl(yinUrl) {
request({
url: yinUrl,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
'Referer': 'http://yys.163.com/tongren/'
}
},function(err, res, body) {
if(!err && res.statusCode === 200){
let result = JSON.parse(body).data.articles;
console.log(result.length);
for(let i = 0; i< result.length; i++){
let url = result[i].body[0].fp_data.url;
let title = `${result[i].id}`;
savePic(url, title);
}
}
})
}
function savePic(url, title){
console.log(`存储图片-->${title}`);
request(url).pipe(fs.createWriteStream(`./gif/${title}.jpg`));
console.log(`图片${title}-->存储完成啦!`);
}