Backbencher.dev

How To Get Content of First Child Using Node.js and Cheerio

Last updated on 6 Aug, 2021

When crawling a web page, we obtained below data.

<div id="productDetails">
  <span>MacBook Air 13"</span>
  <span>$999</span>
</div>

Using cheerio, we need to take the content of first span. Here is how:

$("#productDetails span").first().text();
--- ○ ---
Joby Joseph
Web Architect