首页 > 解决方案 > 使用 PHP 读取 Zillow XML 文件

问题描述

我有一个想要阅读的 XML 文件,但似乎无法理解它。

要访问我提取的文件,您可以输入:

http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZWz1gyo1562s5n_6sext&address=155+Demar+Blvd&citystatezip=Canonsburg%2C+PA

我正在通过 PHP 执行此操作,因此我的代码如下所示:

<html>

<head>
<title>Hellow World</title>
</head>
<body>


<?php
$zillow_id = 'X1-ZWz1gyo1562s5n_6sext';

$search = '155 Demar Blvd';
$citystate = 'Canonsburg PA';
$address = urlencode($search);
$citystatezip = urlencode($citystate);

$url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=$zillow_id&address=$address&citystatezip=$citystatezip";

$result = file_get_contents($url);
$data = simplexml_load_string($result);

echo $data->response->results->result->lotSizeSqFt . "<br>";

?>

</body>
</html>

我曾预计此代码会导致将批量大小(以平方英尺为单位)打印到屏幕上。没有骰子。

但是,代码行:

echo $data->response->results->result->zpid . "<br>";

返回 zpid 参数的预期值:49785503。

在理想世界中,代码行:

echo $data->response->results->result->lotSizeSqFt . "<br>";

将返回:9000。

我究竟做错了什么?

标签: phphtmlxmlzillow

解决方案


您在代码中使用了错误的端点。

您的端点: http://www.zillow.com/webservice/GetSearchResults.htm

正确的端点: http://www.zillow.com/webservice/GetDeepSearchResults.htm

使用GetDeepSearchResults将返回您正在寻找的结果。


推荐阅读