0

我有一个脚本,可以将 Zillow 中的数据提取到谷歌文档中……见下文。它已经工作了几年,但最近停止工作。它似乎可以运行,但需要很长时间并且没有填充数据。Zillow ID 位于活动工作表的 B 列中,根据脚本,Zestimate 应写入第 48 列。我已将 ZWS-ID 替换为“X1-XXXXXXXXX_XXXX”

任何帮助是极大的赞赏。

谢谢猕猴桃

function getZillowEstimates() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();

  var specificRow = ""
  var endRow;
  if(specificRow == "")
  {
    specificRow = 1; 
    endRow = numRows;
  }
  else
  {
    specificRow = specificRow - 1;
    endRow = specificRow;
  }
  for (var i = specificRow; i <= endRow; i++)
  {
    try
    {
      var row = values[i];
      var response = UrlFetchApp.fetch("http://www.zillow.com/webservice/GetZestimate.htm?zws-id=X1-XXXXXXXXX_XXXX&zpid=" + row[1]);   
      var xmlDoc = XmlService.parse(response.getContentText());
      var documentElement = xmlDoc.getRootElement();
      var destinationRange = sheet.getRange(i + 1, 48, 1, 1);
      if( null != documentElement )
      {
        var responseElement = documentElement.getChild("response");
        if (null != responseElement)
        {
          var zestimateElement = responseElement.getChild("zestimate");
          if( null != zestimateElement)
          {
            var amountElement = zestimateElement.getChild("amount");
            if( null != amountElement)
            {
              var rowValue = [];
              var cellValue = [];
              cellValue.push(amountElement.getText());
            }
          }
        }
      }
      else
      {
        cellValue.push("Not Found");
      }
      rowValue.push(cellValue);
      destinationRange.setValues(rowValue);
    }
    catch(exception)
    {

    }
  }
};



/**
 * Adds a custom menu to the active spreadsheet, containing a single menu item
 * for invoking the readRows() function specified above.
 * The onOpen() function, when defined, is automatically invoked whenever the
 * spreadsheet is opened.
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var menuItems = [
    {name: 'Get ZEstimate', functionName: 'getZillowEstimates'},
   ];
  spreadsheet.addMenu('Zestimates', menuItems)
};
4

1 回答 1

0

今天它正在工作。昨天脚本需要 6 分钟才能运行,今天是 1.6 秒。我猜 Zillow 或 API 有问题。

于 2016-07-01T21:08:16.177 回答