Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erajanraja24/02279e405e28311f220f557156363d7b to your computer and use it in GitHub Desktop.
Save erajanraja24/02279e405e28311f220f557156363d7b to your computer and use it in GitHub Desktop.
Scraping google search results
function scrapeGoogle() {
var searchResults=UrlFetchApp.fetch("https://www.google.co.in/search?q="+encodeURIComponent("amarindaz youtube channel"));
var titleExp=/<h3 class=\"r\">([\s\S]*?)<\/h3>/gi;
var titleResults=searchResults.getContentText().match(titleExp);
// Logger.log(titleResults);
for(var i in titleResults)
{
var actualTitle=titleResults[i].replace(/(^\s+)|(\s+$)/g, "").replace(/<\/?[^>]+>/gi, "");
Logger.log(actualTitle);
}
}
@user3691
Copy link

It does not work anymore. Google blocks bot searches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment