Google script to extract data from a web page

Google script to extract data from a web page

Cancelled

Job Description

Hi I am trying to get the following data from the yahoo page into excel

http://biz.yahoo.com/z/20130809.html

Company Symbol Surprise (%) Reported EPS Consensus EPS

I am struggling with RegEx on Google Script to clean the tags/text around the data I need. Here is my code and the google spreadsheet

https://docs.google.com/spreadsheet/ccc?key=0AkIgDsf5Go2XdHpaTDZJV29qSlFUMTJsdGZ5VThoY2c#gid=0


function addEarningsSurprises(){

//url exampls is

var sSheet = SpreadsheetApp.getActiveSpreadsheet();
sheet = SpreadsheetApp.setActiveSheet(sSheet.getSheets()[0]);

var date = "20130809";

var url = "http://biz.yahoo.com/z/"+date+".html";
// var url = "http://biz.yahoo.com/z/20130809.html";

Logger.log("url is "+ url );
try{

var response = UrlFetchApp.fetch(url).getContentText();
tempA = response.split("All rights reserved");
Logger.log("completed fetchingthe main content");
tempB = tempA[0].split("<td><small>");
var j = 1 ;
var ticker = ""
var companyName = "";
Logger.log("number of entries is" + tempB.length);

for(j = 1; j < 5; j++){
Logger.log("j is" + j + "tempB is " + tempB[j]);
var stockdata = tempB[j];
var tempC = stockdata.split("</small></td><td");
companyName = tempC[0];
Logger.log("comapnyName is" +companyName);

regExp = new RegExp(/(">)(.+?)(<\/a>)/g);

ticker = tempC[1].match(regExp);

Logger.log("ticker is" + ticker);

// regExp = new RegExp(/">/);

// ticker = ticker.replace(regExp, "");
//
// Logger.log("ticker is" + ticker);

var regExp1 = new RegExp(/(align=right><small>)(.+)/);

var surprise = tempC[2].match(regExp1);

Logger.log("surprise is" + surprise);

var reportedEPS = tempC[3].match(regExp1);

Logger.log("reportedEPS is" + reportedEPS);

var consensesEPS = tempC[4].match(regExp1);

Logger.log("consensesEPS is" + consensesEPS);

sheet.appendRow([companyName,ticker,date, surprise,reportedEPS,consensesEPS]);
}

}catch(e){

}

}

Other open jobs by this client