I am trying to get the API from a website called zillow working for me, but I am way new to web stuff. They try and explain here how to use it, but it had me lost so I looked in their forums. Someone posted an "example" there, but I can not see where their code even calls the API. Basically I need to take a form field that will be an address and send that info to get data back, here is the source code taken from the guys example,
我试图从一个名为zillow的网站获取API为我工作,但我对网络新东西是新手。他们试着在这里解释如何使用它,但它让我失去了所以我看着他们的论坛。有人在那里发布了一个“示例”,但我看不出他们的代码甚至调用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> </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> </td>
</tr>
</table>
<div align="center">
<input name="submit" type="submit" value="Get Zestimate">
</div>
</form>
You can see it is just a simple form that posts to itself right? But when I hit go it pulls the data from the API and displays it, but I do not see how. I would love any help you can offer, thank you!
您可以看到它只是一个简单的表单,自己发布了吗?但是当我点击它时,它会从API中提取数据并显示它,但我不知道如何。我很乐意为您提供任何帮助,谢谢!
2 个解决方案
#1
5
Based on http://www.zillow.com/howto/api/APIFAQ.htm#devkit, there is no JavaScript API. Because of this (and cross-domain restrictions) you have to use a server-side language. I'll add a simple Java example.
基于http://www.zillow.com/howto/api/APIFAQ.htm#devkit,没有JavaScript API。由于这个(以及跨域限制),您必须使用服务器端语言。我将添加一个简单的Java示例。
EDIT: Okay, here goes. It just takes the street address and city/state, and returns a formatted value. Error-checking left out:
编辑:好的,这里。它只需要街道地址和城市/州,并返回格式化的值。错误检查遗漏:
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));
}
}
#2
0
Nahhh... this way is MUCH easier :-)
Nahhh ......这种方式更容易:-)
Build two functions and use them like this for zillow. The response that comes back is very plain.
构建两个函数并像zillow一样使用它们。回复的反应很简单。
string zWsid = "yourZwsid";
// sample API Call
// http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=<ZWSID>&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA
string response = string.Empty;
int iZpid = 0;
int iLotSizeSqFoot = 0;
int iHomeValue = 0;
float estimate = 0;
try {
response = web_url("http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=" + zWsid + "&address=" + addressTB.Text + "&citystatezip=" + CityStateZipTB.Text);
} catch (Exception ex) {
MessageBox.Show("Exception occured! " + ex.ToString());
}
// MessageBox.Show(response);
try {
iZpid = Int32.Parse(parseTag(response, "zpid"));
}
/// you can make a lot of the calls and catch a lot of the values back just like this :-)
///// Functions/////
private string parseTag(string response, string tag) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(response);
XmlNodeList elemList = doc.GetElementsByTagName(tag);
string parsedTag = elemList[0].InnerXml;
return parsedTag;
}
private string web_url(string url) {
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
// MessageBox.Show(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
// MessageBox.Show(responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();
return responseFromServer;
}
#1
5
Based on http://www.zillow.com/howto/api/APIFAQ.htm#devkit, there is no JavaScript API. Because of this (and cross-domain restrictions) you have to use a server-side language. I'll add a simple Java example.
基于http://www.zillow.com/howto/api/APIFAQ.htm#devkit,没有JavaScript API。由于这个(以及跨域限制),您必须使用服务器端语言。我将添加一个简单的Java示例。
EDIT: Okay, here goes. It just takes the street address and city/state, and returns a formatted value. Error-checking left out:
编辑:好的,这里。它只需要街道地址和城市/州,并返回格式化的值。错误检查遗漏:
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));
}
}
#2
0
Nahhh... this way is MUCH easier :-)
Nahhh ......这种方式更容易:-)
Build two functions and use them like this for zillow. The response that comes back is very plain.
构建两个函数并像zillow一样使用它们。回复的反应很简单。
string zWsid = "yourZwsid";
// sample API Call
// http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=<ZWSID>&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA
string response = string.Empty;
int iZpid = 0;
int iLotSizeSqFoot = 0;
int iHomeValue = 0;
float estimate = 0;
try {
response = web_url("http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=" + zWsid + "&address=" + addressTB.Text + "&citystatezip=" + CityStateZipTB.Text);
} catch (Exception ex) {
MessageBox.Show("Exception occured! " + ex.ToString());
}
// MessageBox.Show(response);
try {
iZpid = Int32.Parse(parseTag(response, "zpid"));
}
/// you can make a lot of the calls and catch a lot of the values back just like this :-)
///// Functions/////
private string parseTag(string response, string tag) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(response);
XmlNodeList elemList = doc.GetElementsByTagName(tag);
string parsedTag = elemList[0].InnerXml;
return parsedTag;
}
private string web_url(string url) {
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
// MessageBox.Show(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
// MessageBox.Show(responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();
return responseFromServer;
}