Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!