办学质量监测教学评价系统
ageer
2024-05-17 7fe89a931b291196b0b571c668bd3758309019d7
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
34
35
36
37
38
const https = require('https')
const fs = require('fs')
 
const options = {
  hostname: 'www.bing.com',
  port: 443,
  path: '/HPImageArchive.aspx?format=js&idx=0&n=8',
  method: 'GET'
}
 
const req = https.request(options, bing_res => {
  let bing_body = [], bing_data = {};
  bing_res.on('data', (chunk) => {
    bing_body.push(chunk);
  });
  bing_res.on('end', () => {
    bing_body = Buffer.concat(bing_body);
    bing_data = JSON.parse(bing_body.toString());
    let img_array = bing_data.images;
    let img_url = [];
    img_array.forEach(img => {
      img_url.push(img.url);
    });
    var jsonpStr = "getBingImages(" + JSON.stringify(img_url) + ")";
    fs.writeFile('./assets/json/images.json', jsonpStr, (err) => {
      if (err) {
        throw err;
      }
      console.log("JSON data is saved: " + jsonpStr);
    });
  });
})
 
req.on('error', error => {
  console.error(error)
})
 
req.end()