I’m trying to get the specific text strings below as separated outputs e.g. (scrape them from the HTML below):
let text = "Thats the first text I need";
let text2 = "The second text I need";
let text3 = "The third text I need";
I really don’t know how to get a text that’s separated by different HTML tags.
<p>
<span class="hidden-text"><span class="ft-semi">Count:</span>31<br></span>
<span class="ft-semi">Something:</span> That's the first text I need
<span class="hidden-text"><span class="ft-semi">Something2:</span> </span>The second text I need
<br><span class="ft-semi">Something3:</span> The third text I need
</p>
2
Answers
Try something like this and see if it works:
Using your sample html, the output should be:
You can iterate the child nodes of the
<p>
and grab anynodeType === Node.TEXT_NODE
s that have nonempty content:In Cheerio: