从 Zillow API 中提取 Zillow Rent 数据 [英] Pulling Zillow Rent Data from Zillow API
问题描述
我正在使用 Zillow API,但在检索租金数据时遇到问题.目前我正在使用 Python Zillow 包装器,但我不确定它是否适用于提取租金数据.
I am playing around with the Zillow API, but I am having trouble retrieving the rent data. Currently I am using a Python Zillow wrapper, but I am not sure if it works for pulling the rent data.
这是我用于 Zillow API 的帮助页面:https://www.zillow.com/howto/api/GetSearchResults.htm
This is the help page I am using for the Zillow API: https://www.zillow.com/howto/api/GetSearchResults.htm
import pyzillow
from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults
import pandas as pd
house = pd.read_excel('Housing_Output.xlsx')
### Login to Zillow API
address = ['123 Test Street City, State Abbreviation'] # Fill this in with an address
zip_code = ['zip code'] # fill this in with a zip code
zillow_data = ZillowWrapper(API KEY)
deep_search_response = zillow_data.get_deep_search_results(address, zip_code)
result = GetDeepSearchResults(deep_search_response)
# These API calls work, but I am not sure how to retrieve the rent data
print(result.zestimate_amount)
print(result.tax_value)
<小时>
添加附加信息:
第 2 章讨论如何通过创建名为 zillowProperty 的 XML 函数来提取租金数据.我在 XML 方面的技能不是很好,但我认为我需要:
Chapter 2 talks how to pull rent data by creating a XML function called zillowProperty. My skills going into XML aren't great, but I think I need to either:
a) 导入一些 xml 包以帮助阅读b) 将代码保存为 XML 文件并使用 open 函数读取文件
a) import some xml package to help read it b) save the code as an XML file and use the open function to read the file
https://www.amherst.edu/system/files/media/Comprehensive_Evaluation_-_Ningyue_Christina_Wang.pdf
我试图在此处提供代码,但由于某种原因它不会让我中断到下一行.
I am trying to provide the code in here, but it won't let me break to the next line for some reason.
推荐答案
通过查看 的属性,我们可以看到租金不是一个可以使用
通过运行 pyzillow
包获得的字段>resultdir(result)
,以及这里的代码:Pyzillow 源代码.
We can see that rent is not a field one can get using the pyzillow
package, by looking into the attributes of your result
by running dir(result)
, as well as the code here: Pyzillow source code.
但是,由于开源的美妙之处,您可以编辑此包的源代码并获得您正在寻找的功能.方法如下:
However, thanks to the beauty of open source, you can edit the source code of this package and get the functionality you are looking for. Here is how:
首先,找到代码在您的硬盘驱动器中的位置.导入 pyzillow
,然后运行:
First, locate where the code sits in your hard drive. Import pyzillow
, and run:
pyzillow?
File
字段为我显示了这一点:
The File
field shows this for me:
c:\programdata\anaconda3\lib\site-packages\pyzillow\__init__.py
因此转到 c:\programdata\anaconda3\lib\site-packages\pyzillow
(或它显示的任何内容)并打开 pyzillow.py
文件一个文本编辑器.
Hence go to c:\programdata\anaconda3\lib\site-packages\pyzillow
(or whatever it shows for you) and open the pyzillow.py
file with a text editor.
现在我们需要做两个改变.
Now we need to do two changes.
一:在get_deep_search_results
函数中,您将看到params
.我们需要编辑它以打开 rentzestimate
功能.所以将该函数更改为:
One: Inside the get_deep_search_results
function, you'll see params
. We need to edit that to turn the rentzestimate
feature on. So change that function to:
def get_deep_search_results(self, address, zipcode):
"""
GetDeepSearchResults API
"""
url = 'http://www.zillow.com/webservice/GetDeepSearchResults.htm'
params = {
'address': address,
'citystatezip': zipcode,
'zws-id': self.api_key,
'rentzestimate': True # This is the only line we add
}
return self.get_data(url, params)
二:转到class GetDeepSearchResults(ZillowResults)
,并将以下内容添加到attribute_mapping
字典中:
Two: Go to class GetDeepSearchResults(ZillowResults)
, and add the following into the attribute_mapping
dictionary:
'rentzestimate_amount': 'result/rentzestimate/amount'
瞧!定制和更新的 Python 包现在返回 Rent Zestimate!让我们试试:
Voila! The customized&updated Python package now returns the Rent Zestimate! Let's try:
from pyzillow.pyzillow import ZillowWrapper, GetDeepSearchResults
address = ['11 Avenue B, Johnson City, NY']
zip_code = ['13790']
zillow_data = ZillowWrapper('X1-ZWz1835knufc3v_38l6u')
deep_search_response = zillow_data.get_deep_search_results(address, zip_code)
result = GetDeepSearchResults(deep_search_response)
print(result.rentzestimate_amount)
正确返回 $1200 的 Rent Zestimate,可以在 该地址的 Zillow 页面.
Which correctly returns the Rent Zestimate of $1200, which can be validated at the Zillow page of that address.
这篇关于从 Zillow API 中提取 Zillow Rent 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!