代码之家  ›  专栏  ›  技术社区  ›  Digital Farmer

如何在cheerio中使用“NOT Contains”?

  •  0
  • Digital Farmer  · 技术社区  · 3 年前

    我使用cheeriogs库在谷歌应用程序脚本中工作:
    脚本ID: 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
    https://github.com/tani/cheeriogs

    我当前尝试使用not contains的代码如下所示:

    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());}); 
    }
    

    但给出了一个错误:

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

    考虑到没有括号缺失,并且for not的模型中包含一些cheerio用户指示的正是添加括号的等号,我应该怎么做才能解决这个问题?

    0 回复  |  直到 3 年前
        1
  •  2
  •   pguardiario    3 年前

    您需要:before包含,因为它是一个伪,所以它是

    a:not(:contains(text))