Skip to content

Instantly share code, notes, and snippets.

@marshyon
Last active February 4, 2023 16:32
Show Gist options
  • Save marshyon/376ef9cf53aec8c3d8a19e6115eda325 to your computer and use it in GitHub Desktop.
Save marshyon/376ef9cf53aec8c3d8a19e6115eda325 to your computer and use it in GitHub Desktop.
simple node js app that can read in html, parse it and substitute known elements with new ones using cheero / JQuery of the days of yore
const cheerio = require('cheerio')
const htmlContent = `
<div class="rounded-sm shadow-xl p-10 shadow-md text-center bg-slate-100 text-primary box">
<div class="text-3xl pb-7 font-serif">CONTACT</div>
<div class="pb-5 prose-xl">How to contact me</div>
<article class="md:prose-lg prose-sm break-words">
<p>We&#x27;ll arrange a short telephone conversation and then work out the best options for you.</p>
<p>Please email me</p>
<p><a href="mailto:anne.brookes@canalsidecoach.app">anne.brookes@canalsidecoach.app</a></p>
<p>I am a qualified NLP Coach and Practitioner. I use strategies that bring about real change - techniques called &quot;Creating your future&quot; or Time Line TherapyTM.</p>
</article>
</div>
`
const $ = cheerio.load(htmlContent)
// find all the links
const links = $('a:contains("anne.brookes@canalsidecoach.app")')
.replaceWith('<h1><a href="mailto:anne.brookes@canalsidecoach.app">!!!EMAIL LOGO!!!</a></h1>')
links.each((i, link) => {
// get the href attribute
const href = $(link).attr('href')
console.log(`email link : ${href}`)
})
console.log('htmlContent : ')
console.log($.html())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment