Finding HTML element by ID


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 ;


Have you read some article's on the subject like


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:

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

function getSport() {
var here = "lacrosse";
var target = "";
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');
+ " = "
+ found.getValue()); /// here = lacrosse


I am no expert...

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