gpt4 book ai didi

xml - 如何使用 zillow.com API 将数据发送到 API 调用并将其取回

转载 作者:数据小太阳 更新时间:2023-10-29 01:56:58 28 4
gpt4 key购买 nike

我正在尝试从为我工作的名为 zillow 的网站获取 API,但我对网络内容还很陌生。他们尝试解释 here如何使用它,但它让我迷路了,所以我查看了他们的论坛。有人在那里发布了一个“示例”,但我什至看不到他们的代码在哪里调用 API。基本上我需要采用一个作为地址的表单字段并发送该信息以取回数据,这是从家伙示例中获取的源代码,

<html xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<h3><font face="Verdana, Arial, Helvetica, sans-serif">Get Property < # >Zestimates
from Zillow</a></font></h3>
<form method="post" action="/Real-Estate/Zestimate.php" name="zip_search">
<table align="center" width="618">
<tr>
<td colspan="2"><font face="verdana, arial, sans-serif">Please specify the
Property address. </font></td>

<td width="205" align="left"> <div align="left"><font face="Verdana, Arial, Helvetica, sans-serif"><#></a></font></div></td>
</tr>
<tr>
<td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif">Street</font>:
<input id="street2" type="text" maxlength="50" size="50" value="" name="street"/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><font face="verdana, arial, sans-serif">City, State or ZipCode:</font>
<input id="citystatezip3" type="text" maxlength="50" size="20" value="" name="citystatezip"/></td>

<td>&nbsp; </td>
</tr>

</table>
<div align="center">
<input name="submit" type="submit" value="Get Zestimate">
</div>
</form>

您可以看到它只是一个简单的发布到自身的表单,对吗?但是当我点击 go 时,它会从 API 中提取数据并显示它,但我不知道如何操作。我很乐意提供任何帮助,谢谢!

最佳答案

基于 http://www.zillow.com/howto/api/APIFAQ.htm#devkit , 没有 JavaScript API。由于这个(和跨域限制),您必须使用服务器端语言。我将添加一个简单的 Java 示例。

编辑:好的,开始吧。它只需要街道地址和城市/州,并返回一个格式化的值。遗漏错误检查:

import java.text.NumberFormat;

import org.w3c.dom.*;
import org.xml.sax.*;

import javax.xml.parsers.*;

import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

import java.io.*;

import java.util.Currency;

public class Zillow
{
private static final DocumentBuilderFactory dbFac;
private static final DocumentBuilder docBuilder;
static
{
try
{
dbFac = DocumentBuilderFactory.newInstance();
docBuilder = dbFac.newDocumentBuilder();
}
catch(ParserConfigurationException e)
{
throw new RuntimeException(e);
}
}
private static final String DEEP_URL = "http://www.zillow.com/webservice/GetDeepSearchResults.htm";
private static final String ZESTIMATE_URL = "http://www.zillow.com/webservice/GetZestimate.htm";

private static final String ZWSID = ...;

private static final NumberFormat nf = NumberFormat.getCurrencyInstance();

// Returns Zestimate value for address.
public static String getValuation(String address, String cityStateZip) throws SAXException, IOException
{
Document deepDoc = docBuilder.parse(DEEP_URL +
"?zws-id=" + ZWSID +
"&address=" + address +
"&citystatezip=" + cityStateZip);
Element firstResult = (Element)deepDoc.getElementsByTagName("result").item(0);
String zpid = firstResult.getElementsByTagName("zpid").item(0).getTextContent();
Document valueDoc = docBuilder.parse(ZESTIMATE_URL +
"?zws-id=" + ZWSID +
"&zpid=" + zpid);
Element zestimate = (Element)valueDoc.getElementsByTagName("zestimate").item(0);
Element amount = (Element)zestimate.getElementsByTagName("amount").item(0);
String currency = amount.getAttribute("currency");
nf.setCurrency(Currency.getInstance(currency));
return nf.format(Double.parseDouble(amount.getTextContent()));
}

public static void main(String[] args) throws Throwable
{
String address = args[0];
String cityStateZip = args[1];
System.out.println(getValuation(address, cityStateZip));
}
}

关于xml - 如何使用 zillow.com API 将数据发送到 API 调用并将其取回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1090659/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com