Node.js 잡기 (파충류) 다른 사람의 인터페이스 (get,post) 데이터 얻기 Excel 생성

1969 단어 nodeexclexlsxpost
const xlsx = require('node-xlsx')//xlsx  
const fs =  require('fs') // 
const request = require("request");//request 
let data = [] //  excel   
request({
    url: "https://qudao.youzan.com/resource/department/list",// 
    method: "post",//  post get
    json: true,
    headers: {
        "content-type": "application/json",
        "Cookie":""// cookie
    },
    body: {"page":1,"pageSize":3,"sortAsc":false,"sortKey":"lastVisitTime","prodLineId":2},// post    get  url 
}, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        // console.log(body)
        const rows = body.data.items
        let title = ['address','alias','bindDisplayName','boundTime','customerAlias','customerId','customerName','infoSourceName'
        ,'predictedReleaseReason','region','unboundTime','mobile','name']// 
        data.push(title) //    
        rows.forEach((e) => {
            let arrInner = []
            arrInner.push(e.address)
            arrInner.push(e.alias)
            arrInner.push(e.bindDisplayName)
            arrInner.push(e.boundTime)
            arrInner.push(e.customerAlias)
            arrInner.push(e.customerId)
            arrInner.push(e.customerName)
            arrInner.push(e.infoSourceName)
            arrInner.push(e.predictedReleaseReason)
            arrInner.push(e.region)
            arrInner.push(e.unboundTime)   
            data.push(arrInner)
        });
        writeXls(data)
    }
}); 



//  xlsx 
function writeXls(datas) {
    let buffer = xlsx.build([
    {
        name:'sheet1',
        data:datas
    }
    ]);
    fs.writeFileSync('./data.xlsx',buffer,{'flag':'w'});// excel data excel 
}

좋은 웹페이지 즐겨찾기