Finding HTML element by ID


#1

I'm struggling with a function I'm trying to create. The function would scan the page of a URL and return "lacrosse" (or any elementID) if that word is found in the page. I'm writing this in the google apps script to call the URL with URLFetchApp. It's not coming back that it's valid function. Any ideas? Thanks!

function sports ()
{
var sport ;
try {
sport = UrlFetchApp .fetch(uri) .getContentText() .getElementByID("lacrosse") .toString() ;
}
finally {
return sport ;
}
}


#2

@bytecoder90287,
Have you read some article's on the subject like
http://stackoverflow.com/questions/16862134/google-apps-script-urlfetchapp-and-jquery


#3

Thanks for passing that along. I've looked at a few posts on there but still haven't been able to run my function successfully. This is another post I've been using: http://stackoverflow.com/questions/16695034/does-google-apps-script-have-something-like-getelementbyid/16702114#16702114

I tried to adapt it to my scenario but getting a ReferenceError: "txt" is not defined.

function getSport() {
var here = "lacrosse";
var target = "http://indylacrosseclub.com/";
var pageTxt = UrlFetchApp .fetch(target).getContentText();
var pageDoc = Xml.parse(pageTxt,true);

// Get the receieved xml response into an XML document
var doc = XmlService.parse(txt);

var found = getDivById(doc.getElement(),'here');
Logger.log(found.getAttribute(attr).getValue()
+ " = "
+ found.getValue()); /// here = lacrosse
}


#4

@bytecoder90287
I am no expert...
But IMHO
with

var pageTxt = UrlFetchApp .fetch(target).getContentText();
var pageDoc = Xml.parse(pageTxt,true);

pageDoc is the XML document, as Xml.parsed() the pageTxt

Here another link
http://stackoverflow.com/questions/17769438/xbrl-into-google-spreadsheets-using-google-script