Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MatthiasKunnen
Last active April 14, 2023 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasKunnen/6f9342d6dbf3d6b139bbbbcc233fdf23 to your computer and use it in GitHub Desktop.
Save MatthiasKunnen/6f9342d6dbf3d6b139bbbbcc233fdf23 to your computer and use it in GitHub Desktop.
Removing all non local scripts from HTML using cheerio
const dom = cheerio.load(html);
dom('script').each((index, item) => {
if ('src' in item.attribs && !item.attribs.src.startsWith('http')) {
dom(item).remove();
}
});
const editedDom = dom.html();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment