Google apps script 错误:URL内容中的资源已超过最大大小。-是否可以通过脚本复制IMPORTXML以避免此类问题?
甚至在今天早些时候,它工作得很好,显示了所有的数据。但从现在起,即使我尝试导入一些非常简单的内容,也会出现相同的错误,例如:Google apps script 错误:URL内容中的资源已超过最大大小。-是否可以通过脚本复制IMPORTXML以避免此类问题?,google-apps-script,google-sheets,google-sheets-formula,google-sheets-importxml,Google Apps Script,Google Sheets,Google Sheets Formula,Google Sheets Importxml,甚至在今天早些时候,它工作得很好,显示了所有的数据。但从现在起,即使我尝试导入一些非常简单的内容,也会出现相同的错误,例如: =IF(ARRAYFORMULA(JOIN("-",TRIM(IMPORTXML("http://old.statarea.com/","//tr[3]/th[2]/b | //tr[3]/th[3]/b | //tr[3]/th[7]/b | //tr[3]/th[8]/b | //tr[3]/th[9]/b | //tr[3]/th[16]/b"))))="Host-
=IF(ARRAYFORMULA(JOIN("-",TRIM(IMPORTXML("http://old.statarea.com/","//tr[3]/th[2]/b | //tr[3]/th[3]/b | //tr[3]/th[7]/b | //tr[3]/th[8]/b | //tr[3]/th[9]/b | //tr[3]/th[16]/b"))))="Host-Guest-1-X-2-2.5",
{IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[2]/a"),
IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[3]/a"),
ARRAYFORMULA(VALUE(TEXT(1/QUERY(SUBSTITUTE(IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[7]"),"HX",""),"Where Col1 is not null"),"0.00"))),
ARRAYFORMULA(VALUE(TEXT(1/QUERY(SUBSTITUTE(IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[8]"),"H2",""),"Where Col1 is not null"),"0.00"))),
ARRAYFORMULA(VALUE(TEXT(1/QUERY(SUBSTITUTE(IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[9]"),"HX",""),"Where Col1 is not null"),"0.00"))),
ARRAYFORMULA(VALUE(TEXT(1/QUERY(SUBSTITUTE(IMPORTXML(IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href"),"//tr/td[16]"),"hc2",""),"Where Col1 is not null"),"0.00")))},
"Off")
我想知道是否有可能通过Google应用程序脚本(GAS)复制此导入(我在问题开始处输入的完整导入),如果有人能向我展示它的外观,这样就不会有更多的限制问题。- 您想将问题中的公式转换为Google Apps脚本
- 基本URL是
http://old.statarea.com/
- 您希望通过使用
和IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
导入XML(“http://old.statarea.com/“,”//tr/td/a[5]/@href”)
- 作为值,您需要检索
、td[7]
、td[8]
和td[9]
td[16]
- 例如,您希望将
的检索值计算为50%
,并希望将其用作放入电子表格的值1/0.5
=样本(5)
的公式放入单元格
=IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href")
- 设置
时,数据URL与var placeOfUrl=“4”
IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
- 设置
时,数据URL与var placeOfUrl=“5”
IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[5]/@href”)
- 我确认在你共享的电子表格中的气体项目中使用了V8。所以上面的脚本也使用了V8。请小心这个
- 当来自“”的HTML数据的大小接近1 MB时,可以使用您的公式。但是,当来自“”的HTML数据的大小接近2MB时,就会发生错误。你的问题中已经提到了这一点
- 在这种情况下,URL似乎已更改。当“”中的HTML数据大小接近1 MB时,
与var placeOfUrl=“4”
。但是当来自“”的HTML数据的大小接近2MB时,IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
与来自var placeOfUrl=“5”
。但关于这种情况,我不确定这种情况是否总是发生。我为此道歉IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
- 在这种情况下,URL似乎已更改。当“”中的HTML数据大小接近1 MB时,
- 更改URL页面的规格时,无法使用脚本。所以请小心这个
- 您想将问题中的公式转换为Google Apps脚本
- 基本URL是
http://old.statarea.com/
- 您希望通过使用
和IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
导入XML(“http://old.statarea.com/“,”//tr/td/a[5]/@href”)
- 作为值,您需要检索
、td[7]
、td[8]
和td[9]
td[16]
- 例如,您希望将
的检索值计算为50%
,并希望将其用作放入电子表格的值1/0.5
=样本(5)
的公式放入单元格
=IMPORTXML("http://old.statarea.com/","//tr/td/a[4]/@href")
- 设置
时,数据URL与var placeOfUrl=“4”
IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
- 设置
时,数据URL与var placeOfUrl=“5”
IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[5]/@href”)
- 我确认在你共享的电子表格中的气体项目中使用了V8。所以上面的脚本也使用了V8。请小心这个
- 当来自“”的HTML数据的大小接近1 MB时,可以使用您的公式。但是,当来自“”的HTML数据的大小接近2MB时,就会发生错误。你的问题中已经提到了这一点
- 在这种情况下,URL似乎已更改。当“”中的HTML数据大小接近1 MB时,
与var placeOfUrl=“4”
。但是当来自“”的HTML数据的大小接近2MB时,IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
与来自var placeOfUrl=“5”
。但关于这种情况,我不确定这种情况是否总是发生。我为此道歉IMPORTXML(“http://old.statarea.com/“,”//tr/td/a[4]/@href”)
- 在这种情况下,URL似乎已更改。当“”中的HTML数据大小接近1 MB时,
-
function myFunction() { var placeOfUrl = "5"; // Here, you can change the URL for retrieving values. // Retrieve URL. var baseUrl = "http://old.statarea.com/"; 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 = ' </td>'; 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]; 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(/\ \;|<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 && [6, 7, 8, 15].includes(j)) { ar2.push(Math.round((1 / (parseInt(v, 10) / 100)) * 100) / 100); } } } } return ar2; }, []); ar1.push(temp); return ar1; }, []); // Put values to Spreadsheet. var sheetname = "Sheet5"; var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetname); sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length).setValues(values); }