Home > Enterprise >  How to work with 'NOT Contains' in cheerio?
How to work with 'NOT Contains' in cheerio?

Time:03-02

I use the cheeriogs library to work in Google App Script:
Script ID: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
https://github.com/tani/cheeriogs

My current code trying to use not contains looks like this:

function myFunction() {
  var sheet = SpreadsheetApp.getActive().getSheetByName('Seu Seriado');
  var url = 'https://seuseriado.org/';

  const contentText = UrlFetchApp.fetch(url).getContentText();
  const $ = Cheerio.load(contentText);
  
    $('h2.entry-title.h6 > a:not(contains("SEM LEGENDA"))')
        .each((index, element) => {sheet.getRange(index 1,1).setValue($(element).text().trim());}); 
}

But an error is given:

SyntaxError: missing closing parenthesis in :not ("SEM LEGENDA"))

What should I do to resolve this issue taking into account that no parentheses are missing and the model for not contains that some cheerio users indicate is exactly the one with equal sign adding parentheses?

CodePudding user response:

You need the : before contains since it's a pseudo, so it's

a:not(:contains(text))

  • Related