Python Web Scraping Real Estate Data
The Complete Guide to Web Scraping Real Estate Data
Blog
Use Cases
Summary
Web scraping is now an integral part of the real estate industry. Both agents and regular folks gain much from scrapers. Here’s how you do it:
Jul 14, 2021
9 min read
The property market is constantly expanding, and with it, real estate agents and businesses try to find new solutions to pinpoint what the future holds. While real estate, in general, doesn’t change drastically overnight, it’s affected by way too many factors for one person or even an organization to keep track, will the prices rise or will they go down? What neighborhoods are in high demand? Are there properties that just need a makeover to skyrocket their value? These are just a few of the questions real estate agents are frequently asking answer these questions, one needs loads of research data for comparison, and to manually gather such amounts of information would be like a wild goose chase. Here is where web scraping comes in handy, it collects and structures data as fast as you can say:As we all know by now, web scraping is the powerhouse of data extraction! So, if you want to know more about why anybody would want to scrape real estate data from the Internet and how to do it properly, let’s continue our journey together. We’ve prepared both a DIY solution and a step-by-step guide on how WebScrapingAPI can do you should scrape real estate dataScraping the web will ensure that the extracted information about real estate is precise, credible, and up to date. This way, one can predict if the real estate market will skyrocket any time soon or see in what price range their property will businesses, web data is valuable because it leads to better decisions, better pricing, and a more significant profit margin. However, the catch is that each bit of information needs to be as fresh as possible, making web scraping the obvious most commonly extracted types of real estate data are the following:Property typeSale priceLocationSizeAmenitiesMonthly rental priceParking spacesProperty agentThe information listed above can make or break a real estate agency. It makes a huge difference in communication, strategy, and efficiency, but the biggest advantage is how well agents get to know their properties and market. After that, it’s just a matter of finding the right ’s take a look at a few scenarios that illustrate the value of web scraping:Real estate agenciesDecision-making: Taking risks is part of the job, but that doesn’t mean you must do it blindly. Researching before buying or selling something is mandatory to work, and more info means better edicting the market: It is crucial to know when to buy and sell properties to get the best and most profitable outcome. Some types of properties soar in popularity while others lose their luster. Some areas flourish while others stagnate. Knowing what’s around the corner is the key to longevity as a gular folkWeb scraping isn’t all about helping businesses. Actually, part of what makes it so popular is how easy it is for a single person to use. Sure, you need some knowledge of computer science, but there are plenty of tutorials to help. Heck, this is one of them! Buying and selling: You need to accurately deduce the property’s value before buying or selling it. It would be a shame to sell your childhood home and see it a week later on a real estate website at double the price, wouldn’t it? Investing: If you like to invest in properties, either by buying at a small price to sell it later for profit or simply rent the property, it is highly recommended to know fast you’ll break even and what returns you should, that’s enough on use cases. Let’s look at some code! For starters, let’s assume we are searching for a new home in New York City. We want to buy a property with at least two bedrooms and, of course, a bathroom. So, we’ll start our search on Realtor, extract data from there and compare it to find the best are various ways one can extract content from web pages. This article will explain two methods: one in which we create our web scraper from scratch and one in which we use an already existing, let’s try to do it ourselves. The code will later prove helpful once we use a professional web scraping tool. I chose to write in Python because of how popular it is in web scraping. We have a general-purpose tutorial for extracting web data in Python that you should check out! Inspect the website codeThe data we need to extract can be found in the nested tags of the said webpage. Before we start scraping, we need to find it. To do this, simply right-click on the element and select “Inspect. ”A “Browser Inspector Box” window will pop up, like this:In this window, we will navigate to find the tags and classes under which our essential data can be found. It might seem a bit intimidating at first, but it only gets easier with experience! We can see that everything we need to extract is within the
from bs4 import BeautifulSoup
import pandas as pdTo extract the data from the website, we have to load it by configuring the webdriver to use the Chrome browser. To do this, we simply need to specify the path where the chromedriver is located. Don’t forget to add the name of the executable at the end – not just its location! driver = (‘your/path/here/chromedriver’)Besides the number of beds and bathrooms, we can also extract the address, price, and, why not, the size of the property? The more information we have, the easier it will be to decide on a new home. Declare the variables and set the URL of the to be scraped = []
beds = []
baths = []
sizes = []
addresses = []
(”)We need to extract the data from the website, which is located in the nested tags as explained earlier. Find the tags with the previously mentioned attributes and store the data in the variables declared above. Remember that we only want to save properties with at least two beds and one bathroom! content = ge_source
soup = BeautifulSoup(content, features=”)
for element in ndAll(‘li’, attrs={‘class’: ‘component_property-card’}):
price = (‘span’, attrs={‘data-label’: ‘pc-price’})
bed = (‘li’, attrs={‘data-label’: ‘pc-meta-beds’})
bath = (‘li’, attrs={‘data-label’: ‘pc-meta-baths’})
size = (‘li’, attrs={‘data-label’: ‘pc-meta-sqft’})
address = (‘div’, attrs={‘data-label’: ‘pc-address’})
if bed and bath:
nr_beds = (‘span’, attrs={‘data-label’: ‘meta-value’})
nr_baths = (‘span’, attrs={‘data-label’: ‘meta-value’})
if nr_beds and float() >= 2 and nr_baths and float() >= 1:
()
if price and
else:
(‘No display data’)
if size and
if address and
(‘No display data’)Great! We have all the information we need, but where should we store it? This is where the pandas library comes in handy and helps structure the data into a csv file for us to use in the = Frame({‘Address’: addresses, ‘Price’: prices, ‘Beds’: beds, ‘Baths’: baths, ‘Sizes’: sizes})
_csv(”, index=False, encoding=’utf-8′)If we run the code, a file named ‘’ will be created, and in it, our precious data! We did it! We created our own web scraping tool! Now let’s jump right into it and see what steps we need to follow and which lines of code we need to modify to use a scraping a web scraping APIFor this scenario, we will use WebScrapingAPI, of a free WebScrapingAPI accountTo make use of WebScrapingAPI, you need to create an account. Don’t worry, the first 5000 API calls are free, and you don’t need to share any personal data, like credit card info. After you successfully create your account and validate your email, we can move to the next KeyTo use WebScrapingAPI, you will need to authenticate via the private API Key, which you can find on your account dashboard. Note that you mustn’t share this key with anyone, and if you suspect that it has been compromised, you can always reset the key by pressing the “Reset API Key” the codePerfect! Now that you have the API Key, let’s make the necessary won’t be using a webdriver anymore. Instead, the ‘requests’ library will send the request to WebScrapingAPI and retrieve the website’s HTML code as a requests
import pandas as pdNext, we have to prepare a few parameters for the request: the url of the website we wish to extract data from (realtor) and our API = ”
params = {
“api_key”: “XXXXXXX”,
“url”: “}
response = quest(“GET”, url, params=params)Don’t forget to change which content beautifulsoup is parsing. Instead of the source from the chromedriver, we will use the response received from the ntent = response. textFrom this point on, you can use the same code from the previous scenario. The data will still be stored in a CVS file named ‘’All done! And that’s pretty much it; you can run the code. WebScrapingAPI will do the job, and you’ll get the necessary data to find the perfect home. But you might ask yourself: “What is the difference between using WebScrapingAPI and the scraper we built ourselves? ”. Well, allow me to vs. Pre-madeOne of the most significant advantages of using WebScrapingAPI is its proxies. The service has a huge rotating proxy pool that ensures its users’ anonymity while surfing the feature is also helpful when someone wishes to scrape a website en masse. Making multiple requests on a website in a short amount of time will surely block your IP, thinking it is a grief attempt or a bot with bad a rotating proxy pool will make the website think that multiple users are interacting with it, so you remain undetected and can scrape all day more obstacles can come your way when scraping the web, such as CAPTCHAs or browser fingerprinting. As you might expect, we built WebScrapingAPI to side-step all those hurdles and make data extractions as easy as possible for you. If you want to know more about this topic, check out our article on the most common problems web scrapers can all agree that scraping the web is an excellent solution for the real estate industry, but you can use it for other purposes as well. Here are just a few examples: monitoring your competition, comparing product prices, and training machine learning algorithms. I could go on, but that’s already a whole new subject. I won’t drag this article on forever, so I recommend you check out these seven use cases for web scraping eating a web scraping tool in your free time sounds pretty neat, but there are many things to consider, things that will burn a considerable amount of development time. Here you can find an in-depth discussion about DIY vs. pre-made web scraping we are talking about scraping a few web pages, building the tool yourself can be a fast solution. Still, a professional job needs a professional tool, ideally an API, WebScrapingAPI. Did I mention the free trial?
Is Web Scraping Illegal? Depends on What the Meaning of the Word Is
Depending on who you ask, web scraping can be loved or hated.
Web scraping has existed for a long time and, in its good form, it’s a key underpinning of the internet. “Good bots” enable, for example, search engines to index web content, price comparison services to save consumers money, and market researchers to gauge sentiment on social media.
“Bad bots, ” however, fetch content from a website with the intent of using it for purposes outside the site owner’s control. Bad bots make up 20 percent of all web traffic and are used to conduct a variety of harmful activities, such as denial of service attacks, competitive data mining, online fraud, account hijacking, data theft, stealing of intellectual property, unauthorized vulnerability scans, spam and digital ad fraud.
So, is it Illegal to Scrape a Website?
So is it legal or illegal? Web scraping and crawling aren’t illegal by themselves. After all, you could scrape or crawl your own website, without a hitch.
Startups love it because it’s a cheap and powerful way to gather data without the need for partnerships. Big companies use web scrapers for their own gain but also don’t want others to use bots against them.
The general opinion on the matter does not seem to matter anymore because in the past 12 months it has become very clear that the federal court system is cracking down more than ever.
Let’s take a look back. Web scraping started in a legal grey area where the use of bots to scrape a website was simply a nuisance. Not much could be done about the practice until in 2000 eBay filed a preliminary injunction against Bidder’s Edge. In the injunction eBay claimed that the use of bots on the site, against the will of the company violated Trespass to Chattels law.
The court granted the injunction because users had to opt in and agree to the terms of service on the site and that a large number of bots could be disruptive to eBay’s computer systems. The lawsuit was settled out of court so it all never came to a head but the legal precedent was set.
In 2001 however, a travel agency sued a competitor who had “scraped” its prices from its Web site to help the rival set its own prices. The judge ruled that the fact that this scraping was not welcomed by the site’s owner was not sufficient to make it “unauthorized access” for the purpose of federal hacking laws.
Two years later the legal standing for eBay v Bidder’s Edge was implicitly overruled in the “Intel v. Hamidi”, a case interpreting California’s common law trespass to chattels. It was the wild west once again. Over the next several years the courts ruled time and time again that simply putting “do not scrape us” in your website terms of service was not enough to warrant a legally binding agreement. For you to enforce that term, a user must explicitly agree or consent to the terms. This left the field wide open for scrapers to do as they wish.
Fast forward a few years and you start seeing a shift in opinion. In 2009 Facebook won one of the first copyright suits against a web scraper. This laid the groundwork for numerous lawsuits that tie any web scraping with a direct copyright violation and very clear monetary damages. The most recent case being AP v Meltwater where the courts stripped what is referred to as fair use on the internet.
Previously, for academic, personal, or information aggregation people could rely on fair use and use web scrapers. The court now gutted the fair use clause that companies had used to defend web scraping. The court determined that even small percentages, sometimes as little as 4. 5% of the content, are significant enough to not fall under fair use. The only caveat the court made was based on the simple fact that this data was available for purchase. Had it not been, it is unclear how they would have ruled. Then a few months back the gauntlet was dropped.
Andrew Auernheimer was convicted of hacking based on the act of web scraping. Although the data was unprotected and publically available via AT&T’s website, the fact that he wrote web scrapers to harvest that data in mass amounted to “brute force attack”. He did not have to consent to terms of service to deploy his bots and conduct the web scraping. The data was not available for purchase. It wasn’t behind a login. He did not even financially gain from the aggregation of the data. Most importantly, it was buggy programing by AT&T that exposed this information in the first place. Yet Andrew was at fault. This isn’t just a civil suit anymore. This charge is a felony violation that is on par with hacking or denial of service attacks and carries up to a 15-year sentence for each charge.
In 2016, Congress passed its first legislation specifically to target bad bots — the Better Online Ticket Sales (BOTS) Act, which bans the use of software that circumvents security measures on ticket seller websites. Automated ticket scalping bots use several techniques to do their dirty work including web scraping that incorporates advanced business logic to identify scalping opportunities, input purchase details into shopping carts, and even resell inventory on secondary markets.
To counteract this type of activity, the BOTS Act:
Prohibits the circumvention of a security measure used to enforce ticket purchasing limits for an event with an attendance capacity of greater than 200 persons.
Prohibits the sale of an event ticket obtained through such a circumvention violation if the seller participated in, had the ability to control, or should have known about it.
Treats violations as unfair or deceptive acts under the Federal Trade Commission Act. The bill provides authority to the FTC and states to enforce against such violations.
In other words, if you’re a venue, organization or ticketing software platform, it is still on you to defend against this fraudulent activity during your major onsales.
The UK seems to have followed the US with its Digital Economy Act 2017 which achieved Royal Assent in April. The Act seeks to protect consumers in a number of ways in an increasingly digital society, including by “cracking down on ticket touts by making it a criminal offence for those that misuse bot technology to sweep up tickets and sell them at inflated prices in the secondary market. ”
In the summer of 2017, LinkedIn sued hiQ Labs, a San Francisco-based startup. hiQ was scraping publicly available LinkedIn profiles to offer clients, according to its website, “a crystal ball that helps you determine skills gaps or turnover risks months ahead of time. ”
You might find it unsettling to think that your public LinkedIn profile could be used against you by your employer.
Yet a judge on Aug. 14, 2017 decided this is okay. Judge Edward Chen of the U. S. District Court in San Francisco agreed with hiQ’s claim in a lawsuit that Microsoft-owned LinkedIn violated antitrust laws when it blocked the startup from accessing such data. He ordered LinkedIn to remove the barriers within 24 hours. LinkedIn has filed to appeal.
The ruling contradicts previous decisions clamping down on web scraping. And it opens a Pandora’s box of questions about social media user privacy and the right of businesses to protect themselves from data hijacking.
There’s also the matter of fairness. LinkedIn spent years creating something of real value. Why should it have to hand it over to the likes of hiQ — paying for the servers and bandwidth to host all that bot traffic on top of their own human users, just so hiQ can ride LinkedIn’s coattails?
I am in the business of blocking bots. Chen’s ruling has sent a chill through those of us in the cybersecurity industry devoted to fighting web-scraping bots.
I think there is a legitimate need for some companies to be able to prevent unwanted web scrapers from accessing their site.
In October of 2017, and as reported by Bloomberg, Ticketmaster sued Prestige Entertainment, claiming it used computer programs to illegally buy as many as 40 percent of the available seats for performances of “Hamilton” in New York and the majority of the tickets Ticketmaster had available for the Mayweather v. Pacquiao fight in Las Vegas two years ago.
Prestige continued to use the illegal bots even after it paid a $3. 35 million to settle New York Attorney General Eric Schneiderman’s probe into the ticket resale industry.
Under that deal, Prestige promised to abstain from using bots, Ticketmaster said in the complaint. Ticketmaster asked for unspecified compensatory and punitive damages and a court order to stop Prestige from using bots.
Are the existing laws too antiquated to deal with the problem? Should new legislation be introduced to provide more clarity? Most sites don’t have any web scraping protections in place. Do the companies have some burden to prevent web scraping?
As the courts try to further decide the legality of scraping, companies are still having their data stolen and the business logic of their websites abused. Instead of looking to the law to eventually solve this technology problem, it’s time to start solving it with anti-bot and anti-scraping technology today.
Get the latest from imperva
The latest news from our experts in the fast-changing world of application, data, and edge security.
Subscribe to our blog
A Comprehensive Guide to Extract Zillow with Python | DataOx
Table of Contents
Introduction
Why Choose Python
Scraping Zillow Using Python and LXML
Python tools you will need
Common steps
Running the Zillow data scraper
Scraping Zillow Using Python and BeautifulSoup
Required libraries
Bypassing captchas
Looping through URLs
Formatting data
Summary
The real estate market is one of the most dynamic fields, where data
scraping plays its major role not only for real estate business owners and
agencies but also for regular customers. When we need to make some
decision regarding buying or renting properties, the first thing we should
do is a comparative analysis based on price, type of house, its size,
location, etc.
Therefore, we’re going to scrape the leading real estate marketplace
called Zillow. There are several paid Zillow data scrapers in the market
that you can buy and use, but in this article, we are going to scrape
Zillow with the help of Python. So, if you have some coding skills and do
not want to pay the extra money, let’s move forward to learn how to
download data from Zillow.
As we’ve mentioned above, if you have some coding skills and a bit of
knowledge about web scraping, then you can develop your Zillow data
scraper to extract the required data from Zillow. You can use any
programming language to handle HTML files, but Python is widely used for
developing scrapers. Some facts:
For scraping Zillow with Python, it is required to have Python 3 and Pip
installed. Follow the instructions below for the purpose
As we are using Python 3, it is also required to install the following
packages for downloading and parsing the HTML code. Here are the package
requirements:
We are going to search and scrape Zillow data based on a specific postal
code: 02128.
The whole scraping process contains the following steps:
Conduct a search on Zillow by inserting the postal code.
Get the search results URL Download HTML code through Python Requests.
Parse the page through LXML.
Export the extracted data to a CSV file.
Let’s name the script that will be used for the script name in
a command line.
So, to get the newest listings, we should run an appropriate script to
sort the relevant arguments for the specific zip code.
In the final step, a CSV file will be created in the same folder as the
script.
In this part, we’ll just go through some useful insights that you can
use while scraping Zillow.
For BeautifulSoup you need to install the required libraries, which can
be done through the file. Just input the complete list
in the file and run the pip install file.
Like many websites, Zillow also throws captchas. That’s why while
deploying a (url) function, it is required to add headers to
the request function. See the below example:
To create variables, there are many ways to loop through URLs. Let’s try
the simplest one. So, if you are planning to extract 5 pages’ data, you
can create 5 soup variables and give them a unique title as in the below
example.
To make the extracted data more readable, just make some formatting
jobs. So, we are going to:
Once you decide to scrape Zillow keep in mind that it uses anti-scraping
techniques like captchas, IP blocking, and honeypot traps to prevent its
data from scraping. Already skilled scraper builders can overcome them, but
for newbies, it can be a challenge.
At DataOx we are always happy to help you with professional advice regarding
extracting real estate data or offer you a customized Zillow scraper that
would meet your business needs. Schedule a free consultation with our expert
and find out how web scraping can help your real estate business grow.
Frequently Asked Questions about python web scraping real estate data
Is Web scraping with Python legal?
So is it legal or illegal? Web scraping and crawling aren’t illegal by themselves. After all, you could scrape or crawl your own website, without a hitch. … Big companies use web scrapers for their own gain but also don’t want others to use bots against them.
How do I scrape data from Zillow with Python?
The whole scraping process contains the following steps:Conduct a search on Zillow by inserting the postal code.Download HTML code through Python Requests.Parse the page through LXML.Export the extracted data to a CSV file.Apr 2, 2021
How do you scrape data from Realtor com?
Scrape real estate data on Realtor.com”Go To Web Page” – open the target web page.Create a pagination loop – scrape all the results from multiple pages.Create a “Loop Item” – loop click into each item on each list.Extract data – select the data for extraction.Start extraction – run the task and get data.Dec 22, 2020