Last active
February 4, 2023 16:32
-
-
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
This file contains hidden or 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 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'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:[email protected]">[email protected]</a></p> | |
<p>I am a qualified NLP Coach and Practitioner. I use strategies that bring about real change - techniques called "Creating your future" or Time Line TherapyTM.</p> | |
</article> | |
</div> | |
` | |
const $ = cheerio.load(htmlContent) | |
// find all the links | |
const links = $('a:contains("[email protected]")') | |
.replaceWith('<h1><a href="mailto:[email protected]">!!!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