我正在使用Zillow API,但我在检索租金数据时遇到了困难。目前,我正在使用Python包装器,但我不确定它是否适用于提取租金数据。
这是我为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的技能不是很好,但我认为我需要这样做:
( a)导入一些xml包以帮助读取它b)将代码保存为XML文件,并使用打开的函数读取文件
我试图在这里提供代码,但由于某些原因,它不会让我进入下一行。
发布于 2019-07-12 03:37:28
我们可以看到,通过运行pyzillow来查看result的属性,以及这里的代码:Pyzillow源代码,租金不是一个可以使用dir(result)包的字段。
但是,由于开放源码的优点,您可以编辑这个包的源代码并获得您想要的功能。以下是如何:
首先,定位该代码位于硬盘驱动器中的位置。导入pyzillow,并运行:
pyzillow?File字段为我显示了以下内容:
c:\programdata\anaconda3\lib\site-packages\pyzillow\__init__.py因此,转到c:\programdata\anaconda3\lib\site-packages\pyzillow (或它为您显示的任何东西)并使用文本编辑器打开pyzillow.py文件。
现在我们需要做两个改变。
One:在get_deep_search_results函数中,您将看到params。我们需要编辑它来打开rentzestimate功能。因此,将这一职能改为:
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)2:转到class GetDeepSearchResults(ZillowResults),并将以下内容添加到attribute_mapping字典中:
'rentzestimate_amount': 'result/rentzestimate/amount'Voila!自定义和更新的package现在返回RentZ估测!让我们试试:
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美元的RentZ估测值,可以在那个地址的Zillow页面上验证。
https://stackoverflow.com/questions/56993325
复制相似问题