从 Zillow API 中提取 Zillow Rent 数据

bee*_*eee 5 python api zillow

我正在使用 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)
Run Code Online (Sandbox Code Playgroud)

添加附加信息:

第 2 章讨论如何通过创建一个名为 zillowProperty 的 XML 函数来提取租金数据。我在 XML 方面的技能不是很好,但我认为我需要:

a) 导入一些 xml 包以帮助读取 b) 将代码保存为 XML 文件并使用 open 函数读取该文件

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

我试图在这里提供代码,但由于某种原因它不会让我中断到下一行。

Fat*_*ici 9

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

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

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

pyzillow?
Run Code Online (Sandbox Code Playgroud)

File字段为我显示了这一点:

c:\programdata\anaconda3\lib\site-packages\pyzillow\__init__.py
Run Code Online (Sandbox Code Playgroud)

因此,转到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)
Run Code Online (Sandbox Code Playgroud)

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

'rentzestimate_amount': 'result/rentzestimate/amount'
Run Code Online (Sandbox Code Playgroud)

瞧!定制和更新的 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)
Run Code Online (Sandbox Code Playgroud)

正确返回 $1200 的 Rent Zestimate,可以在该地址的 Zillow 页面进行验证。

  • 它不会让我对你的答案投票,因为我的声誉点仍然低于 15,但这有效!很好地利用了开箱即用的思维能力! (2认同)
  • 很高兴我能够提供帮助,@BobbyZeydelis。感谢您的客气话! (2认同)