在Google表格中使用ImportXML导入体育数据

时间:2018-09-08 05:05:45

标签: xml xpath google-sheets

我正在尝试从以下网站导入投注数据: https://www.pinnacle.com/en/odds/match/football/usa/nfl

在Chrome ive中使用“检查”功能试图确定指向我所需数据的确切链接。我能做的最好的事情如下:

=IMPORTXML(A5,"//td[@class='game-name name']/span")

这给了我许多变量名,但是没有数据。

理想情况下,我想导入具有所有相关列的表赔率数据。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

要获取用于构建数据表的值,请仔细检查(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电子表格单元格中的数据。这是sample的操作方法。