是否可以使用 Google Apps Script 从我在 DevTools 上看到的代码中获取信息? [英] Is it possible to use Google Apps Script to get an info from the code I see at DevTools?

查看:25
本文介绍了是否可以使用 Google Apps Script 从我在 DevTools 上看到的代码中获取信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是这方面的新手...

I am really newbie at this...

是否可以使用 Google Apps Script 获取本网站的总价值:https://www.tokstok.com.br/checkout/?orderFormId=e4f540f0a5de4e2c8c007bfc0f8e67b3#/cart

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

我只能在使用 DevTools/Elements 时看到值,在view-source"中看不到它代码.

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

谢谢!

推荐答案

Google Apps Script 未将其作为内置功能包含在内.为了能够仅使用服务器端代码来做到这一点,您应该实现一个 无头浏览器:

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.

无头浏览器在类似于流行的网络浏览器的环境中提供对网页的自动控制,但它们是通过命令行界面或使用网络通信来执行的.它们对于测试网页特别有用,因为它们能够以与浏览器相同的方式呈现和理解 HTML,包括样式元素,例如页面布局、颜色、字体选择以及 JavaScript 和 Ajax 的执行,这些元素在使用其他工具时通常不可用.测试方法.

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.

另一种替代方法可能是您使用客户端代码,因为 HTML 服务可用于创建对话框/侧边栏/网络应用程序来为其提供服务,包括 google.script API 支持.后者可用于将来自客户端的一些数据发送到服务器端代码,但具有某些限制,即日期、函数和 DOM 对象不能发送到服务器端,但您可以将它们作为 JSON 传递.

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.

相关

这篇关于是否可以使用 Google Apps Script 从我在 DevTools 上看到的代码中获取信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆