从应用程序中基于html的对象引发的html格式错误

问题描述 投票:0回答:1

[当我尝试在应用程序脚本中显示content.text对象时,我遇到了一个难题,它返回格式错误的html错误,特别是关于我对GET请求的获取]]

https://www.cloudconnect.goog/api/core/v3/contents?count=5&fields=subject,content,links.next,-id,-resources

我得到了我需要的一切,但是content.text位在应用程序脚本中引发了格式错误的html错误。我想使用html并以正确的格式按原样返回文档,并认为我可以使用htmloutput将html正确解析为html到apps脚本,因为需要对其进行清理,但是我认为这是引发格式错误的html对象的原因。如何在不转义html字符的情况下继续?我该如何正确解析呢?有没有人成功地做到这一点?

content.text示例:

<body>
    <!-- [DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006] -->
    <div class=\"jive-rendered-content\">
        <p>Hi,team!</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>When executing attest () of SafetyNet Attestation API, apkPackageName is obtained as a parameter.</p>
        <p>I ran this API several times.</p>
        <p>As a result, the apkPackageName parameter was missing only once.</p>
        <p>In all other execution results, the parameter apkPackageName is present and will not occur again.</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>Why can't I get the apkPackageName when running the SafetyNet Attestation API on a device that has not been
            tampered with?</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>device : Kyocera 704KC</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>Regards,</p>
    </div><!-- [DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006] -->
</body>

任何人都将对如何从此处进行操作有任何指示吗?我的目标是从content.text对象中获取文本,我可以在任何常规编辑器上看到该文本,但由于某种原因,在使用原样返回的html格式时,由于某些原因而无法在apps脚本中看到。

Code.gs

function doGet(request) { 
  return HtmlService.createTemplateFromFile('Page').evaluate();
}

function include(filename) { 
  var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.goog/api/core/v3/contents?count=5&fields=subject,content,links.next,-id,-resources');

  var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim(); 

  data = JSON.parse(data);

  var returnedData = [];

  for(var i in data.list){
    var content = data.list[i];
    var content_subject = JSON.stringify(content.subject);
    var content_text = JSON.stringify(content.content.text);
    returnedData.push(content_subject + "<br />" + "<br />" + textBody(content_text));
  }
  return returnedData;
}

function textBody(content){ // <-- where the error throws on the content_text object
  return HtmlService.createHtmlOutput(content);
}

var entityMap = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;',
  '/': '&#x2F;',
  '`': '&#x60;',
  '=': '&#x3D;'
};

function escapeHtml(string) {
  return String(string).replace(/[&<>"'`=\/]/g, function (s) {
    return entityMap[s];
  });
}

function myFunction() {
  Logger.log(HtmlService
      .createTemplateFromFile('Page')
      .getCode());
}

Page.html


<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('Stylesheet'); ?>
  </head>
   <body>
  <script>
  var responseSubject;
  var responseContent;
    function displayData(responseSubject, responseContent) {
        document.getElementById('output').innerHTML = responseSubject + <br> + responseContent + <br>;
    } 
    google.script.run.withFailureHandler(displayData).withSuccessHandler(displayData).include();
    </script>
  </body>
</html>

请多多帮助。

干杯!

当我尝试在应用程序脚本中显示content.text对象时,我遇到了一个难题,它返回格式错误的html错误,特别是关于我对https:// www。的GET请求的获取。...] >

html google-apps-script output
1个回答
0
投票

此作品:

function htmltest() {
  var html='<body><!--[DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006]--><div class="jive-rendered-content"><p>Hi,team!</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>When executing at test() of Safety NetAttestationAPI, apkPackageName is obtained as a parameter.</p><p>I ran this API several times.</p><p>As a result,the apkPackageName parameter was missing only once.</p><p>In all other execution results,the parameter apkPackageName is present and will not occur again.</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>Whycan\'t I get the apkPackageName when running the Safety NetAttestation API on a device that has not been tampered with?</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>device:Kyocera704KC</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>Regards,</p></div><!--[DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006]--></body>';
  var ui=HtmlService.createHtmlOutput(html).setHeight(500);
  SpreadsheetApp.getUi().showModelessDialog(ui, "HTML Test");
}
© www.soinside.com 2019 - 2024. All rights reserved.