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

Published on 7 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 second span. Here is how:

$("#productDetails span:nth-child(2)").text();