简体   繁体   English

如何将= importxml结果放入Google脚本数组?

[英]how to place =importxml result to a google script array?

Could any one show me how i can add result of =importxml into an array inside google script. 任何人都可以告诉我如何将=importxml结果添加到Google脚本中的数组中。 For example this the request inside google script : 例如,这在google脚本中的请求:

=IMPORTXML("https://www.google.com/search?q=bmw&safe=off&tbs=qdr:d","//h3[@class='r']")

I want later iterate the array to look for specific String! 我想要稍后迭代数组以查找特定的String!

One option you can try is: 您可以尝试的一种选择是:

/* CODE FOR DEMONSTRATION PURPOSES */
function ImportXML2Array() {
  var sheet = SpreadsheetApp.getActiveSheet(),
      range,
      values_array;
  sheet.getRange("A1").setFormula('=IMPORTXML("https://www.google.com/search?q=bmw&safe=off&tbs=qdr:d"; "//h3[@class=\'r\']")');
  range = sheet.getDataRange();
  values_array = range.getValues();
  range.clear();
  Logger.log(values_array);
}
/* CODE FOR DEMONSTRATION PURPOSES */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM