繁体   English   中英

从Zillow API中提取Zillow租金数据

[英]Pulling Zillow Rent Data from Zillow API

我正在使用Zillow API,但我无法检索租金数据。 目前我正在使用Python Zillow包装器,但我不确定它是否适用于提取租金数据。

这是我用于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文件并使用open函数读取文件

https://www.amherst.edu/system/files/media/Comprehensive_Evaluation_-_Ningyue_Christina_Wang.pdf

我试图在这里提供代码,但它不会因为某些原因让我突破到下一行。

我们可以看到租金不是一个可以使用pyzillow包获得的字段,通过运行dir(result)查看result的属性,以及这里的代码: Pyzillow源代码

但是,由于开源的美妙,您可以编辑此包的源代码并获得您正在寻找的功能。 方法如下:

首先,找到代码在硬盘中的位置。 导入pyzillow ,然后运行:

pyzillow?

File字段为我显示:

c:\programdata\anaconda3\lib\site-packages\pyzillow\__init__.py

因此,请转到c:\\programdata\\anaconda3\\lib\\site-packages\\pyzillow (或其显示的任何内容)并使用文本编辑器打开pyzillow.py文件。

现在我们需要做两个改变。

一: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)

二:转到class GetDeepSearchResults(ZillowResults) ,并将以下内容添加到attribute_mapping字典中:

'rentzestimate_amount': 'result/rentzestimate/amount'

瞧! 定制和更新的Python软件包现在返回Rent Zestimate! 我们试试吧:

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页面验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM