Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
In XPATH I use '''...and''' to add an additional criterion, in cheerio is there this option?

I use the cheeriogs library to work in Google App Script:
id library: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0

Using =IMPORTXML('url','xpath') I make the call with this XPATH:

//div[contains(@class,'match-card') and ../../td[@class='score-time ']/a[contains(@href, 'matches')]]

The idea is to collect the div that contain the @class with the word match-card
BUT
he needs to have td linked to @class='score-time' and a contains the @href with the word matches

I tried to find a way to do this with CHEERIOGS but it always returns blank, my attempts were:

    $('tr:contains(td.score-time > a[href^="/matches/"]) > div[class^="match-card"]')
                  .each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
    $('tr td.score-time:contains(a[href^="/matches/"]) > div[class^="match-card"]')
                  .each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});
    $('tr td.score-time > a[href^="/matches/"] > div[class^="match-card"]')
                  .each((index, element) => {ss.getRange(index + 2, 2).setValue($(element).text().trim());});

How I could go about achieving my expected result?

Additional information via requests in the comments:

Example link:

https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/

The expected result is to collect the values in red when there are links embedded in blue:

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In your situation, how about the following modified script?

Modified script:

const values = [];
$("tr.expanded").each((_, element) => {
  var v1 = $(element).find('span').attr('data-value');
  var v2 = $(element).find('td.score-time > a').attr('href');
  if (v2) {
    values.push([Utilities.formatDate(new Date(Number(v1) * 1000), Session.getScriptTimeZone(), "HH:mm"), v2]);
  }
});
console.log(values);

// If you want to put the values to the Spreadsheet, please use this. `ss` from your showing script.
ss.getRange(2, 2, values.length, values[0].length).setValues(values);

Result:

When this script is run for the URL of https://int.soccerway.com/national/finland/suomen-cup/20212022/2nd-round/r67751/, the following result is obtained.

[
  ["19:00","/matches/2022/03/27/finland/suomen-cup/oujk/roi-united/3751971/"],
  ["21:30","/matches/2022/03/27/finland/suomen-cup/puleward-city/tornion-pallo-47/3751969/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/rastaala/valtti/3751935/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/hapk/japs-ii/3751944/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/japs-o35/finland-kumu-junior-team/3751949/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/harjun-potku/sc-riverball/3751963/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/fcs/jyvaskylan-seudun-palloseura/3751965/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/barca/kuopion-elo/3751967/"],
  ["07:00","/matches/2022/03/30/finland/suomen-cup/pallo-kerho-37/pupa-o35/3751968/"]
]
about 4 years ago · Juan Pablo Isaza Denunciar

0

That would be the :has pseudo:

td.day:has(~ td.score-time a[href*="matches"])

This might not be available in the version you're using though

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda