0

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

Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
  • Does this answer your question? [Get the text of the current node only](https://stackoverflow.com/questions/42235516/get-the-text-of-the-current-node-only) – Kos Feb 19 '22 at 21:23
  • Hi @Kos , I looked at this question before asking mine, but unfortunately it didn't solve my problem, anyway thanks for trying to help! – Digital Farmer Feb 19 '22 at 21:27

2 Answers2

1

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:

Kos
  • 4,890
  • 9
  • 38
  • 42
  • Hi @Kos , Thank you for helping me. If you are interested, I have another published question also related to the subject, thanks in advance for your attention! https://stackoverflow.com/questions/71189703/how-to-protect-the-positions-to-place-the-data-in-the-worksheet-when-some-values – Digital Farmer Feb 19 '22 at 22:22
0

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

pguardiario
  • 53,827
  • 19
  • 119
  • 159