How to Get Zillow Rental Listings with Python 2023

In this video, I will show you how to get all rental listings for a Zillow search using Python. This will help you to retrieve data at scale for fast and accurate analysis.

Ariel Herrera 0:00

Are you looking to retrieve rental data for a market? Maybe you're a landlord agent or property manager looking to price an upcoming vacancy. Or perhaps you're a researcher looking to analyze metrics like price to rent ratio. Well in this video, I will show you how to get all rental listings for a Zillow search using Python. This will help you to retrieve data at scale for fast and accurate analysis. My name is Ariel Herrera fellow data scientists with the analytics erielle channel where we bridge the gap between real estate and technology. I love bringing easy to use data driven solutions that you can apply to your business. Please like this video so that we can reach a wider audience and subscribe to this channel so you don't miss out on the latest content. All right, let's get started.

In this video, we're going to accomplish taking a URL from Zillow and being able to get all the property listings in this case rental listings that are in our search. We'll be able to analyze and even download this data as well work with it within Python. So for our use case, I'm going to use Riverview Florida river view is a city outside of Tampa and one that I've lived in and invested in in the past. I'm going to imagine that I'm a landlord that has a property in this given area, and it has an upcoming vacancy. Therefore I need to understand what are the rental rates currently for the given market so I could price my rental fairly when showing its other applicants. Here within my search. I've gone to Zillow, and I've looked at properties for rent. And I've selected properties that are at least 1k elver for rent just to make sure there's no extraneous outliers. I've also looked at properties that are in scope to the property that I have, which is three bedrooms, two baths, as well, I've only selected houses, particularly because houses typically have backyards, and are in certain communities that may be apartments and condos or townhomes or not. And therefore, the price of the rental property could be different. as well. I've also filtered on year built to now I would do the search based on what you're looking for in your particular market. And ultimately, I want to be able to get all these listings. So I want to see the rent rates for each of these properties, the property name, as well as the number of beds, baths, square footage, so I can analyze this within my own spreadsheet. So what we're going to do is now come over to Google collab, and Google collab, we're going to extract this data with Python. Now there's two options here. If you're new to Python, but you don't want to learn how to code, then come over to the tool that I've already built called property search. It's a tool I built in streamlet that allows you to interface with the Zillow API created by scrape peak. So all you have to do is basically come here, you go to your listings, you input the URL, and then within the analytics tab, you can pull previous listings based on your email. So I'm going to pull them based on analytics aerial.com, you'll be able to go to your listings, and you'll see your latest listings that you've made in the last 14 days. In this case, I have one that's for for rental properties. And I'll be able to get information like how many properties were in my search, the average rent price, some charts to understand our distribution and ultimately download the data. Now, what if we want to do this for multiple markets, it's not going to be efficient for us to copy and paste a URL into this tool for say, 20 markets, we need an iterative way to do this. And to do so would be using a programming language like Python. So going back to Google collab, we're going to use collab to code in Python and query data from the Zillow scraper API. If you're new to API's, the basic concept for this case is we use web scraping. So scrape peak is able to go to public data set. So zillow.com They then have a bar that goes to grab information for every property, then they have it where it's structured, and to a certain format where we can query the data and get the information that we'd like. So we don't have to build web scrapers from scratch. And we can access this data simply with an API key and signing up all for free. Once you Click the link below sign up for a free account, you will then see your own personal dashboard. You can go over to scrapers will you'll see your Zillow scraper API, and you could try for free. Under your plans, make sure you select it starter to begin with. This will give you 1000 credits, otherwise known as 100 searches for free per month, you can then upgrade your plan as needed. Next, you go over to account settings, you'll see your information including your email, as well as your current plan, how many plan credits you have, how many have been used, and your API key, your API key is like a password. And it's important for us to now copy this and bring it over into our Python notebook. So now going back to Google collab, you will want to start off by going to File in the upper left hand corner, then clicking save a copy and drive. This will open up Google collab in your own personal workspace. Now, if we go down, let's run the first set of cells. This is importing important libraries that we're going to utilize within this notebook. Then we're going to run these functions. And I'll detail what these functions do in a moment. So the next two steps is to run our locals and constants. So for me, I have my API key within a CSV file. So a file that has rows and columns, I have many API keys, including AWS, and some other API's as well. So I have all my keys, I have a column that says API, and in that I have scrape peak. So I assign my key here using Panda's data frame, I read in my file, and then I locate my API key. Now, if you don't want to follow the steps, that's okay. You could simply delete or ignore these two cells at a cell here, and then put in API underscore key to your API key from your dashboard, and paste it within the strings. So it'll look something like this, than you would run yourself so that now your API key string is assigned to the variable. Great. So I am now going to load in my API key via reading my API keys file. Next, we've already detailed in a previous video on how to get property listings for sale. So we're going to jump down to section number two. And section number two is getting rental property listings for rent. So it's pretty similar to the previous one. And if we go to this function get listings. At the top, I'll explain briefly what we're going to do. So at the Zillow scraper, if we go to API documentation, and we go to listings, we can access all data points of the property from listing using this endpoint, think of endpoint almost like a folder structure and within their folders, different files. And this is one particular file. Imagine that and we're going to be getting information from this file or from this endpoint. So here, we're going to input our API key. So the API needs a way to identify who we are. And then our URL. This is going to come from Zillow. So now going back here, we specify that endpoint, which is above, entering our API key and URL with an query string, which is a dictionary of key value pairs. And then lastly, we're getting that information. So I want to jump back down. Now that we've explained what this function does, on let's go to Zillow. So here we've already filtered on Zillow listings and Riverview, Florida, over 1k, three beds, two baths and single family. I'm going to copy the URL, and I'm going to paste it within the strings in my notebook. It's a really long URL. And that's expected. Now I'm setting this to a variable called rent listings URL, and I pass that into the function get listings. Now if I run play, it's going to get the data from the API.

Now I'm going to view all of my keys from the API. So here, I'm printing and printing out all of my keys, I could see whether the request was successful, the data itself and the message. So if I want to index is success, I transform my object to a JSON object. And then the key is underscore success. And it comes back as true. So yes, we asked the API to get data and it successfully got us back information. Now if we look at the data key, and specifically at total count, we We could see that until there are 73 properties. Next, it's going to be useful for us to actually view this as a table, I like to think think of data like in Excel, rows and columns. So here we're going to transform our data using Pandas, JSON normalize. And again, if this is completely new to you, in terms of utilizing Python in this manner, I highly suggest for you to go through the series of introduction to Python for free on my channel. So I'm going to press play here. And now if we look, we have all of the rental listings of in an instant, we had suddenly two rental listings here. And now, if we see them, we have all the prices, bedrooms, bathrooms, and the status tax, which all it should be for rent, we even get more information, such as the location of the home, if you want to put it into a map view, we could also look at what type the home is, in this case, I requested everything to be a single family home, we can also see the Zestimate and rent Zestimate. And this is really useful because now as a landlord, I can get a gauge as to what other people are listing similar homes for. But a table isn't good enough, it's easier to derive insights from your data through visualization. So now going down below, I can actually view the listing price, and I pass in my data frame, as well as the column for rental price. I put this into a box plot using Plotly Express. And I could see right away that the median rent price is 2450. With upper quartile for q3 Being around 20 720 200. On the lower end, we have some outliers, but particularly with this will tell me is I likely can get 2454 by home, maybe I would want to filter a little bit more on your bill, because the property that I have is within the last five years. So maybe those on the lower end over here are older homes. That's something I could dig in through with the data if I like. Now, if I want to look at Rent Zestimate. I'm going to pass in here, the correct data frame, which is dF ret listings. And I could see the Zestimate meaning what Zillow has established of what the rent is expected to be. The median here is 2400, which is really close to 2450. So you're able to right away, get information from your Zillow search, and be able to analyze this and Python. So a great future use case could be if you're say new to investing, or you want to look at a new market, and you want to compare rent properties, or maybe get price to rent ratio across five different cities, you can then put this logic into a for loop, and iterally get this information all within probably less than five seconds, and you can analyze and compare different markets. If that's something that you want to see me do in the future, then please leave comments below as well. I'd love to hear what markets you're looking to get more data for and any other tools that you're using as well. Thanks for watching. If you haven't already, please subscribe.

Transcribed by https://otter.ai

Previous
Previous

5 Ways ChatGPT Can Help Real Estate Investors

Next
Next

How to Download Rental Listings Data