简体   繁体   中英

Using ImportXML in Google Sheets to import sports data

Im trying to import the betting data from the following website: https://www.pinnacle.com/en/odds/match/football/usa/nfl

Using the Inspect function in Chrome ive tried to identify the exact link to the data i require. The best i can do is the following:

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

This gives me a number of variable names but no data.

Ideally i'd like to import the table odds-data with all the relevant columns.

Can anyone help?

To get the values that are used to build the data table inspect the network tab in the (Chrome) Developer tools carefully and you will find a call 889?callback=angular.callbacks._0 that contains the values as a JSON object wrapped by angular function.

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...

There are several options to get this into Google spreadsheet. The most straightforward, but not necessarily the easiest option is to use the Script Editor to retrieve the response string, extract the JSON string, and then retrieve the data in question from the JSON object. Here is a snippet to get you started:

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
}

First, you need to identify the stuff you want to get from the object; I suspect the data you are looking for can be found under dataAll.Leagues["0"].Events .

The next step would insert the data from the object int spreadsheet cells. Here's a sample how to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM