Google apps script 通过脚本从网站导入数据时隐藏的数据

Google apps script 通过脚本从网站导入数据时隐藏的数据,google-apps-script,web-scraping,google-sheets,Google Apps Script,Web Scraping,Google Sheets,当复制数据时,理论上它应该出现-或X:Y半时结果:Z:A,但是下面显示的一些值是隐藏的,我想知道执行此操作的脚本有什么问题,以及脚本必须如何保持以使其不再发生。只有当游戏结果中有一个V标记(绿色)时,才会显示这些值 站点: 当前结果: 预期结果: 缺少要收集的数据的列如下: 函数示例(placeOfUrl){ //检索URL。 var baseUrl=”http://old.statarea.com/predictions.php"; var res1=UrlFetchApp.fetch

当复制数据时,理论上它应该出现
-
X:Y半时结果:Z:A
,但是下面显示的一些值是隐藏的,我想知道执行此操作的脚本有什么问题,以及脚本必须如何保持以使其不再发生。只有当游戏结果中有一个V标记(绿色)时,才会显示这些值

站点:

当前结果:

预期结果:

缺少要收集的数据的列如下:

函数示例(placeOfUrl){
//检索URL。
var baseUrl=”http://old.statarea.com/predictions.php";
var res1=UrlFetchApp.fetch(baseUrl);
如果(res1.getResponseCode()!=200)抛出新错误(“无法使用URL”);
常量from='';
常数至=“”;
const htmlData1=(from+Parser.data(res1.getContentText()).from(from.to.to.build()+to.replace(/\/g,”);
const xmlRoot=XmlService.parse(htmlData1.getRootElement();
const c=xmlRoot.getChildren()[placeOfUrl-1];
如果(!c)返回;
const url=c.getAttribute(“href”).getValue();
//解析HTML数据。
const res2=UrlFetchApp.fetch(url);
如果(res2.getResponseCode()!=200)抛出新错误(“无法使用检索数据的URL”);
常量htmlData2=res2.getContentText();
const parsedData1=Parser.data(htmlData2.from(“”).to(“”).build();
const parsedData2=Parser.data(parsedData1).from(“”).to(“”.iterate();
const data=parsedData2
.filter(函数(e){return/^/.test(e)})
.map(函数(e){return”“+e.match(//g).map(函数(f){return f.replace(//\\\\\\\\\\\\\\\\\\\&team\\\\\\&g,”)。加入(“”+“”)
.加入(“”);
const xmlRootContent=XmlService.parse(“+data+”).getRootElement();
//检索结果值。
const content=xmlRootContent.getChildren();
常量值=内容减少((ar1,e)=>{
const temp=e.getChildren().reduce((ar2,f,j)=>{
如果(f){
如果(f.getChild(“a”)){
常量t=f.getChild(“a”).getValue()
if(t)ar2.推(t);
}否则{
if(f.getAttribute(“样式”)){
常数v=f.getValue();
如果(v&[5,6,7,8,15],包括(j)){
ar2.推(v);
}
}
}
}
返回ar2;
}, []);
ar1.推送(温度);
返回ar1;
}, []);
返回值;
}
链接到电子表格:

例如,为了实现您的目标,如何修改
值,如下所示

发件人: 致:
我不得不为我糟糕的英语水平道歉。不幸的是,我不能理解你的问题。因为现在,从URL检索的HTML中只包含4个
X:Y半时结果:Z:A
。我能问一下这种情况和你的问题之间的关系吗?另外,我可以问一下你的目标吗?晚安,我的朋友,我刚刚在问题中添加了一个名为“预期结果”的部分,它准确地显示了电子表格中缺少的内容。我不知道为什么,但它只是在结果中有绿色V时复制值。当没有绿色V时,无法复制
-
和其他结果。我只看到您在这里返回值,但没有关于它们如何显示的任何信息,因此很难解决如何以及在何处隐藏它们的问题。Cooper,我在问题中添加了显示哪列数据未完整收集数据的图像,以防我误解了您的需要,很抱歉,我的英语有缺陷。好的,问题不是这些值隐藏在最终显示中,而是它们未被收集。正确吗?
-
正在显示,但是没有绿色V的结果仍然不会返回。。。如:
路易斯维尔城足球俱乐部-圣路易斯足球俱乐部
@Brondby,谢谢您的回复。给您带来不便,我深表歉意。关于
Louisville City FC-圣路易斯FC
,在原始脚本中,尚未检索到该值。“这个怎么样?”布朗德比,谢谢你的回答。不幸的是,我无法复制你目前的情况。那么,您能否提供当前脚本以复制您的问题?因为在我的环境中,不会发生错误。“我对此深表歉意。”布朗德比,谢谢你的回复。我不得不为我糟糕的英语水平道歉。我回答了
对不起。我复制您的原始脚本时添加了一行。我更新了它。
。但你似乎不明白。对此我深表歉意。在当前脚本中,
const content=xmlRootContent.getChildren()不包括在内。这样,就会发生错误。请将它放在
const values=content.reduce((ar1,e)=>{
之前,然后再次测试它。@Brondby如果感谢您的回复和测试。我很高兴您的问题得到解决。也谢谢您。
function sample(placeOfUrl) {
  // Retrieve URL.
  var baseUrl = "http://old.statarea.com/predictions.php";
  var res1 = UrlFetchApp.fetch(baseUrl);
  if (res1.getResponseCode() != 200) throw new Erro("URL cannot be used.");
  const from = '<td style="padding-top: 10px; text-align: center;">';
  const to = '&nbsp;&nbsp;</td>';
  const htmlData1 = (from + Parser.data(res1.getContentText()).from(from).to(to).build() + to).replace(/\&nbsp;/g, "");
  const xmlRoot = XmlService.parse(htmlData1).getRootElement();
  const c = xmlRoot.getChildren()[placeOfUrl - 1];
  if (!c) return;
  const url = c.getAttribute("href").getValue();

  // Parse HTML data.
  const res2 = UrlFetchApp.fetch(url);
  if (res2.getResponseCode() != 200) throw new Erro("URL for retrieving data cannot be used.");
  const htmlData2 = res2.getContentText();
  const parsedData1 = Parser.data(htmlData2).from('<table class="style_1" cellspacing="0" cellpadding="0" width="918" border="0">').to('</table>').build();
  const parsedData2 = Parser.data(parsedData1).from("<tr>").to("</tr>").iterate();
  const data = parsedData2
    .filter(function(e) {return /^<td width="35" align="center">/.test(e)})
    .map(function(e) {return "<content>" + e.match(/<td.+?\/td>/g).map(function(f) {return f.replace(/\&nbsp\;|<div.+?>|<\/div>|<img.+?>|<input.+?>|\&team_guest|<\/h.+?>|\&/g, "")}).join("") + "</content>"})
    .join("");
  const xmlRootContent = XmlService.parse("<root>" + data + "</root>").getRootElement();

  // Retrieve result values.
  const content = xmlRootContent.getChildren();
  const values = content.reduce((ar1, e) => {
    const temp = e.getChildren().reduce((ar2, f, j) => {
      if (f) {
        if (f.getChild("a")) {
          const t = f.getChild("a").getValue()
          if (t) ar2.push(t);
        } else {
          if (f.getAttribute("style")) {
            const v = f.getValue();
            if (v && [5, 6, 7, 8, 15].includes(j)) {
              ar2.push(v);
            }
          }
        }
      }
      return ar2;
    }, []);
    ar1.push(temp);
    return ar1;
  }, []);

  return values;
}
const values = content.reduce((ar1, e) => {
  const temp = e.getChildren().reduce((ar2, f, j) => {
    if (f) {
      if (f.getChild("a")) {
        const t = f.getChild("a").getValue()
        if (t) ar2.push(t);
      } else {
        if (f.getAttribute("style")) {
          const v = f.getValue();
          if (v && [5, 6, 7, 8, 15].includes(j)) {
            ar2.push(v);
          }
        }
      }
    }
    return ar2;
  }, []);
  ar1.push(temp);
  return ar1;
}, []);
const values = content.reduce((ar1, e) => {
  const temp = e.getChildren().reduce((ar2, f, j) => {
    if (f) {
      if (f.getChild("a")) {
        const t = f.getChild("a").getValue();
        if (t) ar2.push(t);
      } else if (f.getChild("span")) {
        ar2.push(f.getValue());
      } else {
        const v = f.getValue();
        if (v && [5, 6, 7, 8, 15].includes(j)) {
          ar2.push(v);
        }
      }
    }
    return ar2;
  }, []);
  ar1.push(temp);
  return ar1;
}, []);