ライブラリからParserを追加
https://script.google.com/macros/s/AKfycby-SbnAWcB_P8h4y1cy4dx8hHHkCTYbONFnXiixYhuXnjhPFwbr/exec
function myFunction() { // スクレイピング const html = UrlFetchApp.fetch('https://web.pref.hyogo.lg.jp/kf16/singatakoronakensa.html').getContentText(); const today = new Date(); // Logger.log(today); // 配列をJSON用に変換 let json = Parser.data(html).from('var dataset=').to(';var start').build().replace(/'/g, '"').replace(/, *?,/g, ', 0,'); // Logger.log(json); let data = JSON.parse(json); // スプレッドシートに書き込み let mySheet = SpreadsheetApp.getActiveSheet(); let result = [] for (let v of data) { for (let i = v.length; i < 5; i++) { v.push(0); } result.push(v); } let lastRow = mySheet.getLastRow(); let rows = data.length; Logger.log(lastRow, rows) // 更新確認 if (lastRow <= rows) { mySheet.getRange(2, 1, rows, 5).setValues(result); } } function getData() { let mySheet = SpreadsheetApp.getActiveSheet(); let rows = mySheet.getDataRange().getValues(); var keys = rows.splice(0, 1)[0]; return rows.map(function (row) { var obj = {} row.map(function (item, index) { obj[keys[index]] = item; }); return obj; }); } function doGet(e) { const data = getData(); return ContentService.createTextOutput(JSON.stringify(data, null, 2)).setMimeType(ContentService.MimeType.JSON); }