TropicalViking
TropicalViking

Reputation: 425

Cheerio : Getting a text from a list

I am scraping a web site and using node and cheerio for that purpose. I have the below structure

<li class="wrap-level-1">
                    <a class="level-2 link" href="https:mysite..." target="_blank"> Tropical Viking </a>
                </li>

How do I get the Tropical Viking text only ?

I am trying this

 $('.wrap-level-1').map((i, el) => {
      console.log('entering scrapper')
      const count = resultCount++
      console.log(count)
      //This is what I need
      const title = $(el).find('a').???
      const metadata = {
        title: title
            }
      parsedResults.push(metadata)
      console.log(metadata)
    })

Thanks for your help

Upvotes: 0

Views: 463

Answers (1)

pguardiario
pguardiario

Reputation: 54987

It looks like you want this:

let parsedResults = $('.wrap-level-1').map((i, el) => {
  console.log('entering scrapper')
  const count = resultCount++
  console.log(count)
  // This is what I need
  const title = $(el).find('a').text()
  const metadata = {
    title: title
  }
  return metadata
}).get()

Upvotes: 1

Related Questions