aidenhera
BANNED
- Joined
- Nov 30, 2016
- Messages
- 3,059
- Reaction score
- 913
I messed with it some and came up with the code below. It mostly works, but is pretty buggy.
If you can fix the bugs and make a few adjustments, it should work.
Code:function checkIfPageIsIndexed(url) { if (!url) return "N/A"; url = "https://www.google.com/search?q=site:"+url; var options = { 'muteHttpExceptions': true, 'followRedirects': false }; var response = UrlFetchApp.fetch(url, options); var html = response.getContentText(); if ( html.match(/Your search -.*- did not match any documents./) ) return "URL is Not Indexed"; // <div id="resultStats">1 result<nobr> (0.21 seconds) </nobr></div> // <div id="resultStats">About 112,000,000 results<nobr> (0.22 seconds) </nobr></div> var num_pages_indexed = false; if ( num_pages_indexed = html.match(/id="resultStats">.*result/) ) { num_pages_indexed = num_pages_indexed[0] + "(s)"; num_pages_indexed = num_pages_indexed.replace("id=\"resultStats\">",""); // num_pages_indexed = num_pages_indexed.replace("<",""); } else num_pages_indexed = "ERROR"; return "URL is Indexed and returned "+num_pages_indexed; }
Example Output
View attachment 100611
I have my code already
Code:
function checkIfPageIsIndexed(url)
{
url = "https://www.google.com/search?q="+url;
var options = {
'muteHttpExceptions': true,
'followRedirects': false
};
var response = UrlFetchApp.fetch(url, options);
var html = response.getContentText();
var arr = html.match(/resultStats">.*? result.../);
return(arr);
}
it simply takes html and returns regex.
its based on your indexing checking code. I noticed that sometimes your code shows "INDEXED" if the string is not found, but sometimes the search is probably not performed because it showed me indexed many times while it was not.
Same with the edition I made. Sometimes it wont show anything, even if it should be there. Maybe google blocks searches from google sheets (just as it blocks from importxml function).
What bugs did you mean? Ill try your code