[英]Import data into Google Sheets using IMPORTXML with the div-class
[英]Using ImportXML in Google Sheets to import sports data
我試圖從以下網站導入投注數據: https : //www.pinnacle.com/en/odds/match/football/usa/nfl
使用 Chrome 中的 Inspect 功能,我試圖確定我需要的數據的確切鏈接。 我能做的最好的是:
=IMPORTXML(A5,"//td[@class='game-name name']/span")
這給了我一些變量名但沒有數據。
理想情況下,我想導入包含所有相關列的表賠率數據。
任何人都可以幫忙嗎?
要獲取用於構建數據表的值,請仔細檢查 (Chrome) 開發人員工具中的網絡選項卡,您會發現調用889?callback=angular.callbacks._0包含值作為由 angular 包裝的 JSON 對象功能。
angular.callbacks._0({"ResponseTime":"2018-09-09T20:19:26Z","OddsType":"american","Leagues":[{"LeagueId":889,"SportId":15,"IsLive":false,"HasLiveLines":true,"Events":[{"EventId":841876318,"LeagueId":889,"SaveTime":"2018-09-10T03:15:47Z","DateAndTime":"2018-09-10T16:10:00Z","Cutoff":"2018-09-10T23:10:00Z","HoursAndMinutes":"16.10","PeriodNumber":0,"IsLive":false,"IsOffline":false,"LiveStatus":2,"Totals":{"OverPrice":104.0,"UnderPrice":-115.0,"Min":45.0},"IsHandicapEmpty":false,"IsMoneyLineEmpty":false,"IsTeamTotalsEmpty":false,"Participants":[{"Id":479,"Name":"New York Jets","Type":"Team1","Handicap":{"Price":-113.0,"Min":7.0},"MoneyLine":256.0,"TeamTotals":{"OverPrice":-110.0,"UnderPrice":-106.0,"Min":17.5},"IsDraw":false},{"Id":480,"Name":"Detroit Lions","Type":"T...
有幾個選項可以將其放入 Google 電子表格。 最直接但不一定最簡單的選項是使用腳本編輯器檢索響應字符串,提取 JSON 字符串,然后從 JSON 對象中檢索有問題的數據。 這是一個讓你開始的片段:
function getJSON(aUrl,sheetname) {
var aUrl = "https://www.pinnacle.com/webapi/1.17/api/v1/GuestLines/Deadball/15/889?callback=angular.callbacks._0";
var response = UrlFetchApp.fetch(aUrl);
var jsonString = response.getContentText().replace("angular.callbacks._0(", "").replace(");", "");
Logger.log(jsonString);
var dataAll = JSON.parse(jsonString); //
var data = dataAll.Leagues["0"].Events;
/*for (i in data){
var overPrice = data[i].Totals.OverPrice;
var underPrice = data[i].Totals.UnderPrice;
var minPrice = data[i].Totals.Min;
//
}*/
//funcs() to insert data into spreadsheet
}
首先,您需要確定要從對象中獲取的內容; 我懷疑您正在尋找的數據可以在dataAll.Leagues["0"].Events
。
下一步將插入來自對象 int 電子表格單元格的數據。 這是如何做到這一點的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.