function myFunction() {
var gen_otp_url = 'http://data.krx.co.kr/comm/fileDn/GenerateOTP/generate.cmd'
// #otp payload
var gen_otp_data = {'locale' : 'ko_KR',
'mktId' : 'STK',
'trdDd' : '20221205',
'money' : '1',
'csvxls_isNo' : 'false',
'name' : 'fileDown',
'url' : 'dbms/MDC/STAT/standard/MDCSTAT03901'};
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : gen_otp_data};
var otp = UrlFetchApp.fetch(gen_otp_url, options);
Logger.log(otp.getContentText())
var csv_url = 'http://data.krx.co.kr/comm/fileDn/download_csv/download.cmd'
var gen_csv_data = {'code' : otp };
var csv_options = {
'method' : 'post',
'contentType': 'application/json',
'muteHttpExceptions': true,
'payload' : gen_csv_data};
var csv = UrlFetchApp.fetch(csv_url, csv_options);
Logger.log(csv.getContentText());
}
I want to load the csv log with this..
Logger.log(csv.getContentText());
When I did the same code on Python, it was a byte code, so I decoded it, but it didn't work on appsscript...
i tried this. it doesn't work...
function to64(arr) {
var bytes = [];
for (var i = 0; i < arr.length; i )
bytes.push(arr[i]<128?arr[i]:arr[i]-256);
return Utilities.base64EncodeWebSafe(bytes)
} // to64
CodePudding user response:
I want to get this.. AqADUIYgYA1S7YNpohdEFcDGdj9Dk3U4 1LksLL0tDQRtSksuLS7Bnxpl86F7dAOkunw9BBwugQaSjGAcH15eTgGZqZmUYRxtFW2OJYnOsQtBgM EFJCxYg3zco1gIgRZqIo4cIzoURnTI8 MmkJ4v/rk8yudrOQ53ef0cNipdpCT2QuimcLoNhc1Lfcxcp2zXt/wiFT3lY4zZLV84P nFYo9mrWvGCVTr7yVbjg2wtc9glyj0xDQ2lZrfrchZWN
but i get this.. from Logger.log(otp.getContentText())
AqADUIYgYA1S7YNpohdEFUP2/gB8rhRtkSnlEoAJIio=
Logger.log(Utilities.base64EncodeWebSafe(otp.getContent())) QXFBRFVJWWdZQTFTN1lOcG9oZEVGUlk5SHIzUDJBUVJKMDYvMnNmQTEvOD0=
CodePudding user response:
function myFunction() {
var gen_otp_url = 'http://data.krx.co.kr/comm/fileDn/GenerateOTP/generate.cmd'
// #otp payload
var gen_otp_data = {'locale' : 'ko_KR',
'mktId' : 'STK',
'trdDd' : '20221205',
'money' : '1',
'csvxls_isNo' : 'false',
'name' : 'fileDown',
'url' : 'dbms/MDC/STAT/standard/MDCSTAT03901'};
var options = {
'method' : 'post',
'payload' : gen_otp_data};
var otp = UrlFetchApp.fetch(gen_otp_url, options);
Logger.log(otp.getContentText())
var csv_url = 'http://data.krx.co.kr/comm/fileDn/download_csv/download.cmd'
var gen_csv_data = {'code' : otp.getContentText() };
var csv_options = {
'method' : 'post',
'muteHttpExceptions': true,
'payload' : gen_csv_data};
var csv = UrlFetchApp.fetch(csv_url, csv_options);
Logger.log(csv.getContentText("cp949"))
}
I removed this, 'contentType': 'application/json',