Skip to content

Instantly share code, notes, and snippets.

@skkut
Last active October 9, 2015 20:42
Show Gist options
  • Save skkut/d48eeaa1cdecdbdf008b to your computer and use it in GitHub Desktop.
Save skkut/d48eeaa1cdecdbdf008b to your computer and use it in GitHub Desktop.
This google script code scrubs a website, gets a particular text value and inserts new row in a google spreadsheet with the date and value. I use this with a daily time-driven trigger to update the spreadsheet and show an interactive graph.
function UpdateDailyGoldValues()
{
//Initialize website url and get content
var dinamalarWS = UrlFetchApp.fetch("http://business.dinamalar.com/gold_silver_rate.asp");
var strs = dinamalarWS.getContentText();
//get string
var index1 = strs.search("<div id=\"selGoldk\"> <span id=\"selGoldkt\"> 22 காரட் 1கி் </span><br>");
var index2 = strs.search("<div style=\"border:none;\" id=\"selGoldk\"> <span id=\"selGoldkt\"> 24 காரட் 10கி் </span> <br>");
var substrs = strs.slice(index1, index2);
var index3 = substrs.search("width:11px;\">");
var index4 = substrs.search("<img style=\"margin:0px 5px;");
var subsubstrs = substrs.slice(index3+13, index4);
//Initialize spreadsheet
var sh = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
//Insert values to spreadsheet
var numrows = sh.getDataRange().getNumRows();
sh.getRange(numrows + 1, 1).setValue(new Date());
sh.getRange(numrows + 1, 2).setValue(subsubstrs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment