32 lines
900 B
JavaScript
32 lines
900 B
JavaScript
const request = require('request');
|
|
|
|
let url = 'https://api.bilibili.com/x/web-interface/ranking/v2?type=all';
|
|
|
|
// 请求 APi 接口
|
|
async function getApiResult(url) {
|
|
var return_data = await new Promise((resolve) => {
|
|
request({
|
|
method: 'GET',
|
|
url: url,
|
|
}, (error, response, result) => {
|
|
console.log("error, response, result", error, response, result);
|
|
if (!error && (response.statusCode == 200)) {
|
|
// 请求成功
|
|
resolve(result);
|
|
} else {
|
|
// 请求失败
|
|
console.log(`error is ${error}`);
|
|
resolve("error");
|
|
}
|
|
});
|
|
});
|
|
// console.log(`return_data is ${JSON.stringify(return_data)}`);
|
|
return return_data;
|
|
}
|
|
|
|
async function main() {
|
|
let result = await getApiResult(url);
|
|
console.log(result);
|
|
}
|
|
main();
|