Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Csv UrlFetchApp zip文件_Csv_Google Apps Script_Google Sheets_Zip - Fatal编程技术网

Csv UrlFetchApp zip文件

Csv UrlFetchApp zip文件,csv,google-apps-script,google-sheets,zip,Csv,Google Apps Script,Google Sheets,Zip,我正在尝试获取一个zip文件,代码如下: var options = { 'method' :'get', 'validateHttpsCertificates' : false, 'escaping': true }; var url = "https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip"

我正在尝试获取一个zip文件,代码如下:

  var options = {
    'method' :'get',
    'validateHttpsCertificates' : false,
    'escaping': true
  };
  var url = "https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip" 
  var zipblob = UrlFetchApp.fetch(url, options).getBlob(); 
  var unzipblob = Utilities.unzip(zipblob); 
并获取不可用的错误地址:https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip

我通常会使用wget下载文件-例如

wget --no-check-certificate 'https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip'
这很好——解压后的文件是csv

在应用程序脚本中尝试了不同的选项值,并使用escaping=false等,但未取得多大成功


我将非常感谢您的帮助!谢谢

这次修改怎么样

修改点: 从您的wget示例命令中,在您的情况下,我认为选项不是必需的。 下载zip文件时,会发现响应头中的mimeType是application/x-zip。对于Utilities.unzip,需要将mimeType修改为application/zip。 在本例中,我使用了setContentTypeFromExtension,因为该文件的文件名包含扩展名。 当上述各点反映到脚本中时,它将变成如下所示

修改脚本: 参考:
我的回答告诉你结果了吗?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想学习解决你的问题。我能为你的问题做些什么吗?如果我的回答对你的处境没有帮助。我必须道歉并修改它。如果你能合作解决你的问题,我很高兴。我想考虑一下解决方案。下面的解决方案会抛出完全相同的错误消息。我想罪犯可能在URL的$FILE中谢谢你的回复。给您带来不便,我深表歉意。当我在我的Google帐户中运行这个修改后的脚本时,可以提取zip文件。网址是https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip。提取文件的文件名、mimeType和文件大小为PPR-ALL.csv、text/csv和49655119字节。如果此信息正确,能否确认脚本和URL并重试?如果发生相同的错误,我担心访问限制。
var url = "https://www.propertypriceregister.ie/website/npsra/ppr/npsra-ppr.nsf/Downloads/PPR-ALL.zip/$FILE/PPR-ALL.zip" 
var zipblob = UrlFetchApp.fetch(url).getBlob(); // Modified
zipblob.setContentTypeFromExtension(); // Added
var unzipblob = Utilities.unzip(zipblob);