I want to get the number of indexed pages for certain domains. Therefore I want to use the "site:" parameter and extract the number of results from the search result page.
I tried it with a Google-apps-script for Google spreadsheets:
function sampleFormula_4() {
const url = "https://www.google.com/search?q=site%3Abenedikt-sahlmueller.de";
try {
const html = UrlFetchApp.fetch(url).getContentText();
return html.match(/<div id="result-stats">(.+?)nobr>/)[1].trim();
} catch (e) {
Utilities.sleep(5000);
const html = UrlFetchApp.fetch(url).getContentText();
return html.match(/<div id="result-stats">(.+?)nobr>/)[1].trim();
}
}
Google Spreadsheet gives me an error 429 - too many requests. I integrated a sleep-time of 5000ms, but Google Search still returns error 429.
All I need is the number of pages for certain URLs in Google's search results. Maybe there is a better way - I can't use the search-api for this as those pages are not part of my GSC.