N
N
Nick Fisher2018-11-28 18:40:03
JavaScript
Nick Fisher, 2018-11-28 18:40:03

How to parse only 1 tag out of many?

Good afternoon. I'm trying to parse a page using cheerio. Everything is fine, but there is a lot of text on the page in p tags and their classes are also the same. How can I get the contents of the first p tag only?

needle.get(url, function(err, response) {
  const data = response.body
  const $ = cheerio.load(data)
  var descr = $('article section div div p').text();
  console.log(descr)
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-28
@dimoff66

var descr = $('article section div div p:first').text();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question