Created
July 3, 2018 00:55
-
-
Save NickWoodhams/720894e2bb6a38cbbc78594df0b2b701 to your computer and use it in GitHub Desktop.
Override Google Limit on IMPORTXML Function in Google Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey it doesnt look like this is working still. Any input? It would be really helpful.