Search code examples
htmlgoogle-apps-scriptweb-scrapinggoogle-sheetscheerio

How to get a specific info on an Html page, using Cheerio on GAS?


I haven't been able to identify any class, id, etc where the code is supposed to get the information from. Here's the html page and the piece of information I should get everyday: enter image description here

...and here's the piece of code I'm trying to use:

    var content = UrlFetchApp.fetch("https://ovoonline.com.br/", options).getContentText();
    const $ = Cheerio.load(content);
    Logger.log($('td[colspan="2"]').text());

This is its selector, but it doesn't output the correct result:

body > table > tbody > tr > td > table > tbody > tr > td:nth-child(2) > table:nth-child(2) > tbody > tr:nth-child(6) > td > table > tbody > tr:nth-child(2) > td:nth-child(2) > table > tbody > tr:nth-child(1) > td:nth-child(1) > table > tbody > tr:nth-child(18) > td > table > tbody > tr:nth-child(2) > td:nth-child(2) > table > tbody > tr > td:nth-child(1)

Thank you!


Solution

  • This worked for me:

        var content = UrlFetchApp.fetch("https://ovoonline.com.br/",options)
                      .getContentText();
    
       const $ = Cheerio.load(content);
       Logger.log($('td[width="45"]').eq(1).text());
    

    Result Log:

    enter image description here