Hi,
I want to create a Google script to check if a given URL is indexed by Google, so I write the following function:
function CheckURLForGoogleIndex(url, activesheet)
{
// Delete the https:// and http:// prefix
var cururl = url.replace("https://", "");
cururl = cururl.replace("http://", "");
var page = UrlFetchApp.fetch(url, {muteHttpExceptions: true}).getContentText();
// Wait for 1 second before starting another fetch
Utilities.sleep(1000);
var number = page.match("did not match any documents");
if (number)
{
activesheet.getSheetByName("Not Google Index").appendRow([url]);
} else
{
activesheet.getSheetByName("Google Index").appendRow([url]);
}
}
However, when debugging the code, after invoking UrlFetchApp.fetch, I can only see the header of the variable page.
I try to test the function with a Google Indexed URL and not indexed URL, but both will return null in page.match function, so both are put in "Google Index" sheet.
What is the problem with my function?
Thanks