0
votes

I am parsing the following XML:

<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.sportsbook.ag/rss/nfl-football" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Sportsbook.com Live Football Betting Odds RSS Feed</title>
    <link>https://www.sportsbook.ag/rss/nfl-football</link>
    <description>Football Betting Feed</description>
    <language>en</language>
          <item>
    <title>Dallas Cowboys @ Minnesota Vikings</title>
    <link>http://www.sportsbook.ag/livesports/nfl</link>
    <description>&lt;strong&gt;12-1-16 8:25 PM&lt;/strong&gt;
Bet on Dallas Cowboys &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116PSA]=Foot-Dalla-Minne-120116|PSA|1|100|115|-7|-115&quot;&gt;-3.5 (-115)&lt;/a&gt;
Money:&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116MLA]=Foot-Dalla-Minne-120116|MLA|1|100|180|0|-180&quot;&gt;-180&lt;/a&gt;
or Minnesota Vikings &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;/selection[Foot-Dalla-Minne-120116PSH]=Foot-Dalla-Minne-120116|PSH|1|100|105|7|-105&quot;&gt;3.5 (-105)&lt;/a&gt;
Money:&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116MLA]=Foot-Dalla-Minne-120116|MLA|1|100|180|0|-180&quot;&gt;+157&lt;/a&gt;.
Totals: &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116TLO]=Foot-Dalla-Minne-120116|TLO|1|100|110|89|-110&quot;&gt;Over 44.5 (-110)&lt;/a&gt;
&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116TLU]=Foot-Dalla-Minne-120116|TLU|1|100|110|89|-110&quot;&gt;Under 44.5 (-110)&lt;/a&gt;</description>
     <pubDate>12-1-16 8:25 PM</pubDate>
 <dc:creator />
 <guid isPermaLink="false" />
  </item>

with the following Google Apps Script:

function stugass() {
  var live = new Array();
  var url = "https://www.sportsbook.ag/rss/nfl-football";
  var parameters = {method : "get", payload : ""};
  var xml = UrlFetchApp.fetch(url, parameters).getContentText();
  var document = XmlService.parse(xml);
  var games = document.getRootElement().getChild('channel').getChildren('item');
  if(document == null) {
    document.getRootElement().getChild('channel').getChildren('item');
  }
  for (var i=0; i < games.length-1; i++) {
    vegas = [];
    var game = games[i];
    vegas.push(game.getChildText('title'));
    vegas.push(game.getChildText('link'));
    vegas.push(game.getChildText('description'));


    live.push(vegas);
    }
    return live;
 }

How do I split up the "BLOB" portion of the 'description' tag into multiple cells in the Google Spreadsheet?

2

2 Answers

1
votes

It's not obvious how far you want to split that field, but here is one way to do it, using split string method with regex argument that splits by HTML tags found in that description. The array returned by this method is filtered to eliminate any whitespace-only pieces.

var description = game.getChildText('description').split(/<\/?strong>|<a href="|">[^<]*<\/a>/);
vegas = vegas.concat(description.filter(function (a) {return a.trim().length;}));
live.push(vegas);

Output looks like

12-1-16 8:25 PM  |   Bet on Dallas Cowboys   |  https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;action=addBet&amp;betTypeId=80&amp;selection[Foot-Dalla-Minne-120116PSA]=Foot-Dalla-Minne-120116|PSA|1|100|105|-7|-105   |  ... 
1
votes

You can keep it simple like this:

function stugass() {
  var live = new Array();
  var url = "https://www.sportsbook.ag/rss/nfl-football";
  var parameters = {method : "get", payload : ""};
  var xml = UrlFetchApp.fetch(url, parameters).getContentText();
  var document = XmlService.parse(xml);
  var games = document.getRootElement().getChild('channel').getChildren('item');
  if(document == null) {
    document.getRootElement().getChild('channel').getChildren('item');
  }
  for (var i=0; i < games.length-1; i++) {
    vegas = [];
    var game = games[i];
    vegas.push(game.getChildText('title'));
    vegas.push(game.getChildText('link'));
    vegas.push(game.getChildText('description').replace(/<a href=\S+\">|<\S+>/g,''));


    live.push(vegas);
    }
    return live;
 }

The output looks like this:

enter image description here