Yahoo财经历史数据爬取脚本报错:Malformed UTF-8 data stringify
爬取Yahoo财经历史数据的Google Apps Script脚本解密失效问题
我编写了一个用于爬取Yahoo财经历史数据的Google Apps Script脚本,但目前解密服务似乎失效了。脚本代码如下:
function Scrapeyahoo(symbol) { //modificación del 27/1/23 hecha por Tanaike const s = encodeURI(symbol); const url = 'https://finance.yahoo.com/quote/' +s +'/history?p=' +s; var html = UrlFetchApp.fetch(url).getContentText().match(/root.App.main = ([\s\S\w]+?);\n/); if (!html || html.length == 1) return; var obj = JSON.parse(html[1].trim()); var key = [...new Map(Object.entries(obj).filter(([k]) => !["context", "plugins"].includes(k)).splice(-4)).values()].join(""); if (!key) return; const cdnjs = "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"; eval(UrlFetchApp.fetch(cdnjs).getContentText()); const obj1 = JSON.parse(CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(obj.context.dispatcher.stores, key))); const header = ["date", "open", "high", "low", "close", "adjclose", "volume"]; const ar = obj1.HistoricalPriceStore.prices.map(o => header.map(h => h == "date" ? new Date(o[h] * 1000) : (o[h] || ""))); return ar }
执行时,在以下代码行出现错误:Malformed UTF-8 data stringify
JSON.parse(CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(obj.context.dispatcher.stores, key)));
数周前@Tanaike曾解决过类似问题,但Yahoo财经似乎又有新的变更,现寻求该问题的解决方案,感谢帮助。
内容的提问来源于stack exchange,提问作者ejooroo
相关产品推荐
相关产品推荐

