Skip to content

Instantly share code, notes, and snippets.

@dannyBuonocore
Last active December 8, 2021 21:19
Show Gist options
  • Save dannyBuonocore/1073a936d86c0410851c6168a9fd1e97 to your computer and use it in GitHub Desktop.
Save dannyBuonocore/1073a936d86c0410851c6168a9fd1e97 to your computer and use it in GitHub Desktop.
Google Sheets script to fetch Alexa ranks
const formatCommas = (num) => num.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
/**
* @customfunction
*/
function IMPORTALEXA(url) {
var output = '';
var fetchedUrl = UrlFetchApp.fetch(
'https://www.alexa.com/siteinfo/' + url,
{ muteHttpExceptions: true }
);
if (fetchedUrl) {
var html = fetchedUrl.getContentText();
if (html.length) {
output = formatCommas(
html.split('global": ')[1].split(',')[0]
);
}
}
Utilities.sleep(1000);
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment