Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
How to collect only the second text value of data returned from an XPATH using CheerioGS?

The sitemap (https://futebolnatv.com.br/jogos-hoje/) looks like this:

<div class="col-md-01">
<div class="col-md-12">
     <span class="label label-default">0</span>
     <img src="https://futebolnatv.com.br/static/times/ba92f23d6f11341548d808a0ec309acc.png" width="25" height="25">
     "Holstein Kiel"
</div>

Using CheerioGS, to collect the text value I use this path:

    let elements_2 = $('tbody > tr > td > div:nth-child(2)')
    elements_2.each((index, value) => {
      sheet.getRange(index+1, 3).setValue($(value).text().trim())
    })

But instead of just the name Holstein Kiel, it's coming with this number that's inserted into <span> that I don't want:

0
Holstein Kiel

The expected return is:

Holstein Kiel

What should I change to resolve this issue?

CheerioGS project:
https://github.com/tani/cheeriogs

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to change your selector from

$(value).text().trim()

to

$(value).contents().last().text().trim()

Explanation: instead of retrieving text of whole matched element, you need to get all its nodes first (via contents()), then get text node you need (via last()). Rest of code is unchanged.


Reference:

  • https://cheerio.js.org/classes/Cheerio.html#contents
  • https://cheerio.js.org/classes/Cheerio.html#last
about 4 years ago · Juan Pablo Isaza Relatório

0

You could also just delete those, sometimes that's faster: $('.label').remove()

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda