E
E
embiid2020-04-23 13:10:06
JavaScript
embiid, 2020-04-23 13:10:06

How to parse the first element of a block?

I use cheerio. For example, in the block there is a -> a. I need the first a tag from this block. But for some blocks that are parsed (the same), the structure inside has a slightly different markup, but I still need them ONLY the first tag a.

let $ = cheerio.load(html)

    const playersNBA = [];
    $('.nba-player-index__row > .nba-player-index__trending-item > a').each((i, link) => {
      const playerHref = link.attribs.href

      playersNBA.push(playerHref)
    })


If I write a:nth-child(n) then it will skip an element that has a different structure, which is not what I would like, how can I change this? :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question