avatarAriel Herrera

Summary

This context provides a Python tutorial on how to use the Bing Web Search API to extract the ZPID field from Zillow listed properties.

Abstract

The Bing Web Search API is a RESTful Web service that can be used with Python to extract web search results quickly. In this tutorial, the use case focuses on extracting the ZPID field from Zillow listed properties, which is useful for real estate investors and wholesalers who need property details to evaluate deals. The tutorial covers the setup process, including signing up for the Bing Web Search API and setting up a Python environment. It then provides a step-by-step guide on how to call the API using Python, including installing and importing required packages, setting up locals and constants, creating a function, and making an API call. The tutorial concludes by showing how to extract the ZPID from the search results.

Bullet points

  • The Bing Web Search API is a RESTful Web service that can be used with Python to extract web search results quickly.
  • The use case for this tutorial is extracting the ZPID field from Zillow listed properties.
  • The ZPID is a unique identifier for properties listed on Zillow’s website.
  • Real estate investors and wholesalers need property details to evaluate deals, and the ZPID is required to get Zillow property details for an address.
  • The tutorial covers the setup process, including signing up for the Bing Web Search API and setting up a Python environment.
  • The tutorial provides a step-by-step guide on how to call the API using Python, including installing and importing required packages, setting up locals and constants, creating a function, and making an API call.
  • The tutorial concludes by showing how to extract the ZPID from the search results.
  • The Bing Web Search API is free to use with options for pricing tiers for high volume searches.
  • The tutorial recommends using Google Colab as a cloud-based Python environment that is free to use.

API Tutorial: How to use Bing Web Search API in Python

Python tutorial on how to get web search results

Web Search API | Microsoft Bing

Need to get web search results fast? Microsoft Bing’s Web Search API is the right application for just that. Bing’s Web Search API combs billions of webpages, images, videos, and news with a single API call.

The Bing Web Search API is a RESTful Web service compatible with most programming languages. In this article, we will cover how to call the API using Python.

Bing Search

Use Case

For our use case, we will extract the ZPID field from Zillow listed properties. The ZPID is the unique identifier for properties listed on Zillow’s website.

Real estate investors and wholesalers need property details to evaluate deals. It is common to work with off-market properties, which may have limited property information.

Off-market properties are homes that are not for sale, or that is for sale but not listed publicly. — Bungalow

This could be a list of home owners that are in pre-foreclosure and motivated to sell their homes. Investors receive a list of the properties in pre-foreclosure, but require more property details.

Property details like price history, lot size, and zoning can be found in web scraping tools like Apify.

In order to get Zillow property details for an address, the ZPID is required. This is where Bing Web Search API comes in! :)

Setup

To get started you will need:

  1. Bing Web Search API subscription key

Sign up for Bing Web Search API

Bing Web Search API
  • Go to Bing Web Search API and click “TRY NOW”
  • Sign into your Microsoft Azure account or create a new account
  • Select “Start with an Azure free trial”
  • Agree to the “subscription agreement” if prompted
  • Add a payment method (you will not be charged if you stay within Free trial limits — 1,000 API calls a month)
  • Name your Bing Search API resource
Azure API
  • At the home page of your resource go to “Manage keys”
Bing Manage Keys
  • Under “Manage Keys” click “Show Keys” and copy the Key 1
  • Key 1 will be your subscription key

Setup Python environment

To call the API we require an environment set up to write Python code.

I highly suggest to use Google Colab. It is a cloud based environment that is free to use. There is no local set up required. Follow the Getting Started With Google Colab tutorial for more information.

Python Tutorial

Check out Quickstart: Use Python to call the Bing Web Search API for additional information.

I. Install packages

!pip install requests

II. Import Packages

# HTTP library - https://docs.python-requests.org/en/latest/
import requests

III. Locals & Constants

Create a variable to store your API key as a string type object.

# subscription key
bing_subscription_key = <enter your key here>

VI. Function

Create a function that requires two parameters:

  1. Subscription Key — specific to the resource
  2. Query — your own web search string
def bing_web_search(subscription_key, query):
    # set parameters
    search_url = "https://api.bing.microsoft.com/v7.0/search"
    headers = {"Ocp-Apim-Subscription-Key": subscription_key}
    params = {
        "q": query,
        "textDecorations": True,
        "textFormat": "HTML"}
    # get response
    response = requests.get(search_url, headers=headers, params=params)
    response.raise_for_status()
    return response.json()

V. API Call

We wan to obtain the ZPID. It is at the end of the URL for the property:

“https://www.zillow.com/homedetails/11226-Spring-Point-Cir-Riverview-FL-33579/125824629_zpid/

The ZPID for this property is 125824629.

Zillow Property

Next, create a string object for the home address. Add “ zillow home details” to the end of the string. This will sort the Zillow result to the top of the search list.

Call the API with both parameters.

# call API
home_address = '11226 Spring Point Cir, Riverview, FL 33579'
search_results = bing_web_search(
    subscription_key, 
    query= home_address + ' zillow home details')

In the search results select the first URL in the list of URLs. It should be the Zillow property link.

url = search_results['webPages']['value'][0]['url']

Next, get the ZPID by splitting the URL to grab the last element in the list.

zpid = [x for x in url.split('/') if 'zpid' in x][0].split('_')[0]

Output:

zpid = '125824629'

Awesome! We now have the ZPID for the property address we searched in the Bing Web Search API.

Conclusion

Bing’s Web Search API is an excellent resource to receive information on search results. It is free to use with options for pricing tiers for high volume searches.

Find more information on pricing tiers view Bing’s resource page:

Real Estate
API
Technology
Python
Programming
Recommended from ReadMedium