please makre the app script in google sheet for checking url is indexed or not
- User
please makre the app script in google sheet for checking url is indexed or not
- Assistant
please makre the app script in google sheet for checking url is indexed or not
Certainly! You can create a Google Apps Script to check if URLs listed in your Google Sheet are indexed by Google. One common approach is to query Google by using site:yoururl on the URL itself and parse the HTML result to see if Google returns a known result for that URL.
However, note that Google does not provide a direct API to check if a URL is indexed. The closest workaround is to perform a site search site:url and check if your URL appears in the results. This is not 100% reliable but widely used.
site:<URL> (converted as a search query).checkUrlsIndexed.function checkUrlsIndexed() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const urlRange = sheet.getRange("A2:A"); // assuming URLs are in column A, starting from A2
const urls = urlRange.getValues();
for (let i = 0; i < urls.length; i++) {
const url = urls[i][0];
if (!url) continue; // skip empty cells
Logger.log(`Checking URL: ${url}`);
const isIndexed = isUrlIndexed(url);
// Write the result in column B (indexed or not)
sheet.getRange(i + 2, 2).setValue(isIndexed ? "Indexed" : "Not Indexed");
// Optional: pause for 1 second to avoid rate limits
Utilities.sleep(1000);
}
}
function isUrlIndexed(url) {
try {
// Construct a search query
// Use the site:<url> query but since <url> is a full URL, for best result extract domain
// Actually, site:url query works better with domain only, but we want to check exact URL,
// so we can enclose the URL in quotes for exact match search.
const query = 'site:' + url;
const searchURL = "https://www.google.com/search?q=" + encodeURIComponent(query);
// Fetch Google search results page content
const response = UrlFetchApp.fetch(searchURL, {
muteHttpExceptions: true,
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
}
});
const html = response.getContentText();
// Check if URL appears in the search results HTML
// We search for the exact URL in the content - if it appears, probably indexed
// (Google search result HTML changes often, so this is a heuristic)
return html.indexOf(url) !== -1;
} catch (e) {
Logger.log("Error checking URL: " + url + " - " + e.toString());
return false;
}
}
checkUrlsIndexed function manually from the Apps Script editor or set a trigger.Utilities.sleep) helps reduce hitting rate limits.If you'd like, I can also provide a basic example using Google Search Console API to check indexing status properly, but it requires setting up API access and Search Console verification. Let me know!
Not yet included in a published release.