Skip to content

Instantly share code, notes, and snippets.

@NickWoodhams
Created July 3, 2018 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NickWoodhams/720894e2bb6a38cbbc78594df0b2b701 to your computer and use it in GitHub Desktop.
Save NickWoodhams/720894e2bb6a38cbbc78594df0b2b701 to your computer and use it in GitHub Desktop.
Override Google Limit on IMPORTXML Function in Google Sheets
function importRegex(url, regexInput) {
var output = '';
var fetchedUrl = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
if (fetchedUrl) {
var html = fetchedUrl.getContentText();
if (html.length && regexInput.length) {
output = html.match(new RegExp(regexInput, 'i'))[1];
}
}
// Grace period to not overload
Utilities.sleep(1000);
return unescapeHTML(output);
}
var htmlEntities = {
nbsp: ' ',
cent: '¢',
pound: '£',
yen: '¥',
euro: '€',
copy: '©',
reg: '®',
lt: '<',
gt: '>',
mdash: '–',
ndash: '-',
quot: '"',
amp: '&',
apos: '\''
};
function unescapeHTML(str) {
return str.replace(/\&([^;]+);/g, function (entity, entityCode) {
var match;
if (entityCode in htmlEntities) {
return htmlEntities[entityCode];
} else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
return String.fromCharCode(parseInt(match[1], 16));
} else if (match = entityCode.match(/^#(\d+)$/)) {
return String.fromCharCode(~~match[1]);
} else {
return entity;
}
});
};
@pakalski
Copy link

Hey it doesnt look like this is working still. Any input? It would be really helpful.

@rokokkopi
Copy link

Also need this -_-

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