我嘗試獲取https://api.llama.fi/charts/Ethereum給出的資料
看起來像
[{"date":"1546560000","totalLiquidityUSD":273845651.27077854},{"date":"1546646400","totalLiquidityUSD":288674544.41292276"2"1USD{8LiquidityUSD":273845651.27077854"2"1000000000000000000000000000000000000000000000000000000000000000000000! "date":"1546819200","totalLiquidityUSD":286168221.103729},{"date":"1546905600","totalLiquidityUSD":285073686.76345384}, ...
當我在 chrome 中打開它時。
在 python 中urllib.request.urlopen()它作業正常。
在 Google 表格中,我嘗試
function myFunction() {
var data = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getResponseCode()
var data2 = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText()
console.log(UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText())
}
這里資料 = 200,但資料 2 = 未定義。我認為這是一個新手問題,但我不熟悉JS或GS。
謝謝你的幫助!
最好的事物,
多米尼克
uj5u.com熱心網友回復:
您可以通過將 ContentText 決議為 JSON 來訪問資料作為 JSON 物件,然后您可以使用 for 迭代資料或以您需要的任何其他方式使用它。
function myFunction() {
var response = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText()
var data = JSON.parse(response);
for(const d of data) {
console.log("DATE: " d.date)
console.log("LIQUIDITY: " d.totalLiquidityUSD)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/345289.html
標籤:javascript 谷歌应用程序脚本 网页抓取 谷歌表格 urlfetch
上一篇:如何正確對齊圖示?
