0

I am really newbie at this...

Is it possible to use Google Apps Script to get the total value of this website: https://www.tokstok.com.br/checkout/?orderFormId=e4f540f0a5de4e2c8c007bfc0f8e67b3#/cart

I can only see the value when I use DevTools/Elements, I can't see it at the "view-source" code.

I was trying this code, but it doesn't return the info:

function getData() {
    const url = 'https://www.tokstok.com.br/checkout/?rderFormId=e4f540f0a5de4e2c8c007bfc0f8e67b3#/cart';
    const fromText = '<span class="x-resume-cart__price-value js--resume-cart-value">';
    const toText = '</span>';
    const content = UrlFetchApp.fetch(url).getContentText();
    const scraped = Parser.data(content).from(fromText).to(toText).build();
    Logger.log(scraped);
    return scraped;
}

Thanks!

Rubén
  • 29,320
  • 9
  • 61
  • 145
Hirata
  • 1
  • The data comes from a xhr, so you probably could get it if you make the right request, but it looks like a pain. – pguardiario Nov 06 '20 at 00:11

1 Answers1

0

Google Apps Script doesn't include that as built-in feature. In order to be able to do that using only server-side code you should have to implement a headless browser:

A headless browser is a web browser without a graphical user interface.

Headless browsers provide automated control of a web page in an environment similar to popular web browsers, but they are executed via a command-line interface or using network communication. They are particularly useful for testing web pages as they are able to render and understand HTML the same way a browser would, including styling elements such as page layout, colour, font selection and execution of JavaScript and Ajax which are usually not available when using other testing methods.

Another alternative might be to u use client-side code as the HTML Service could be used to create a dialog/sidebar/web-application to serve it including google.script API support. The later could be used to send to the server-side code some data from the client-side with certain limitations, i.e. Date, Function and DOM objects can't be sent to server side but you might pass them as JSON.

Related

Rubén
  • 29,320
  • 9
  • 61
  • 145
  • can't you retrieve data from the console? consoleget() or something? – Baby_Boy Nov 05 '20 at 18:35
  • @Baby_Boy Google Apps Script hasn't console.get Ref. https://developers.google.com/apps-script/reference/base/console by the other hand "somehing" is too broad, could you be more specific? – Rubén Nov 05 '20 at 18:49
  • Please bear in mind that this question is about using server-side code :) – Rubén Nov 05 '20 at 18:51
  • sorry I'm not 100% sure what the command would be called if it even existed, which is why I said "or something" I wasn't sure if you knew about or had taken into account a server side version of console.get (probably doesn't exist based on your comments) that runs after the page has loaded client side and then fetched the current console log Edit: Not an expert, I was trying to learn : ) (no offense to you, this is not an attack, but an explanation for my actions) – Baby_Boy Nov 05 '20 at 18:58
  • @Baby_Boy I edited my answer and added the [tag:web-scraping] tag to the question. – Rubén Nov 05 '20 at 19:10