Last active
April 14, 2023 21:26
-
-
Save MatthiasKunnen/6f9342d6dbf3d6b139bbbbcc233fdf23 to your computer and use it in GitHub Desktop.
Removing all non local scripts from HTML using cheerio
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
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