Created
October 8, 2018 21:20
-
-
Save zeke/2b06ef06e2ddaa7e2ec5bf1837b203b8 to your computer and use it in GitHub Desktop.
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 cheerio = require('cheerio') | |
const html = ` | |
<ul> | |
<li>Hello A</li> | |
<li>Hello B</li> | |
<li>Hello C</li> | |
</ul> | |
` | |
const $ = cheerio.load(html) | |
function parse (input) { | |
return Promise.resolve(input.replace('Hello', 'Goodbye')) | |
} | |
console.log($.html()) | |
Promise.all( | |
$('li') | |
.map((i, el) => parse($(el).html())) | |
.get() | |
).then(intros => { | |
console.log(intros) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a variant that actually mutates the
$(el)
HTML on the fly: