php - 使用 PHP 读取 Zillow XML 文件
问题描述
我有一个想要阅读的 XML 文件,但似乎无法理解它。
要访问我提取的文件,您可以输入:
我正在通过 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。
我究竟做错了什么?
解决方案
您在代码中使用了错误的端点。
您的端点:
http://www.zillow.com/webservice/GetSearchResults.htm
正确的端点:
http://www.zillow.com/webservice/GetDeepSearchResults.htm
使用GetDeepSearchResults
将返回您正在寻找的结果。
推荐阅读
- python - python:How do I improve this code(TicTacToe)?
- php - 用于数据库插入的 PHP 拆解数组
- sql - 如何确定 SQL Server“查找孤岛”(连续行)中的连续日期计数/天数
- arrays - 如何检查复杂数组中的相似数据
- linux - 有没有办法“回响”到标准输出什么被重定向为标准输入到程序(Unix)?
- for-loop - if, else if, 有没有更好的方法让我运行这段代码?
- android - Firebase 数据库访问 && 安全规则
- c# - char[] vs char 在方法的参数中。这是 MS 文档中的错误吗?
- mongodb - 如何在 spring-data mongodb 中使用 updateOption 和 arrayFilters?
- c - 列出我声明的函数的 C IDE