How to Scrape Redfin Property Data with Node.js

Tutorial on how to scrape Redfin.

With millions of properties listed on its platform, scraping Redfin is one of the most powerful strategies for real estate firms and analysts to spot market trends and shifts, find investment opportunities, and build a big-picture view of the market as a whole.

However, scraping real estate platforms like Redfin has its challenges, as most of them use anti-scraping mechanisms, such as CAPTCHA challenges, request rate-limiting, and IP address bans – to name a few.

Scrape Property Data from All Major Real Estate Platforms

ScraperAPI helps you unlock real estate data at scale by bypassing all anti-bot detection methods and mechanisms.

In this tutorial, we’ll show you how to extract property listings from Redfin using Node.js, automating the data collection process without getting blocked.

TL;DR: Full Redfin Scraper

For those in a hurry, here is the full Node.js code

	const axios = require('axios');
	const cheerio = require('cheerio');
	
	const REDFIN_PAGE_URL = 'https://www.redfin.com/city/5155/CO/Denver/apartments-for-rent';
	const API_URL = 'https://api.scraperapi.com';
	const API_KEY = '' // <--- Enter your API key here
	
	const webScraper = async () => {
	   console.log('Fetching data with ScraperAPI...');
	
	   const queryParams = new URLSearchParams({
		   api_key: API_KEY,
		   url: REDFIN_PAGE_URL,
		   country_code: 'us'
	   });
	
	   try {
		   const response = await axios.get(`${API_URL}?${queryParams.toString()}`);
	
		   const html = response.data;
	
		   const $ = cheerio.load(html);
		   const propertyList = [];
	
		   console.log('Extracting information from the HTML...');
	
		   $(".HomeCardContainer").each((_, el) => {
			   const price = $(el).find('.homecardV2Price span').text();
			   const beds = $(el).find('.HomeStatsV2 .stats:first-child').text();
			   const bath = $(el).find('.HomeStatsV2 .stats:nth-child(2)').text();
			   const space = $(el).find('.HomeStatsV2 .stats:last-child').text();
			   const address = $(el).find('.homeAddressV2 .fullAddress').text().substring(2);
			   const link = $(el).find('a:has(div.link-and-anchor)').attr('href');
			   const linkText = $(el).find('a:has(div.link-and-anchor)').text();
			   const contact = $(el).find('a.large-phone-cta').text();
	
			   if (!price) {
				   return
			   }
	
			   propertyList.push({
				   price,
				   address: address ?? linkText,
				   beds,
				   bath,
				   space,
				   link: link ? `https://www.redfin.com${link}` : null,
				   contact
			   });
		   });
	
		   console.log('JSON result:', propertyList);
	   } catch (error) {
		   console.log(error)
	   }
	};
	
	void webScraper();

Before running this code, install the dependencies and set your API key, which you can find in your ScraperAPI dashboard.

Don’t have an API key yet? Create a free ScraperAPI account and get 5,000 API credits with your 7-day free trial.

Scraping Redfin Property Listings

For this tutorial, we’ll write a scraper that finds properties for rent in the city of Denver, Colorado. For each property for sale, we will retrieve the following information:

  • Address
  • Price
  • Number of beds
  • Number of bath
  • Surface
  • Property link
  • Contact phone number

The script will return the properties list extracted in JSON format so you can easily use it for other purposes.

Showing results for scraping Redfin property listing

Prerequisites

You must have these tools installed on your computer to follow this tutorial.

Step 1: Set Up Your Project

Let’s create a folder that will contain the source code of the Refin web scraper.

	mkdir redfin-scraper

Enter the folder and initialize a new Node.js project. The second command above will create a package.json file in the folder.

	cd redfin-scraper

	npm init -y	

Next, create a index.js file and add a simple JavaScript instruction inside.

	touch index.js

	echo "console.log('Hello world!');" > index.js	

Run the file index.js using the Node.js runtime.

	node index.js

This execution will print the message Hello world! in the terminal, verifying the installation was successful.

Step 2: Install the Dependencies

Before we can scrape Redfin pages, we must install two Node.js packages:

  • Axios – to build the HTTP request (headers, body, query string parameters, etc…), send it to the ScraperAPI standard API, and download the HTML content.
  • Cheerio – to extract the information from the HTML downloaded with the Axios request.

Run the command below to install these packages:

	npm install axios cheerio

Step 3: Inspect Redfin Result Page

Navigate to https://www.redfin.com. The property for sale is the default option; select the option “Rent” to target houses for rent. Type “Denver” in the search bar and press enter.

Once the property listings load, inspect the page to display the HTML structure and identify the DOM selector associated with the HTML tag wrapping the information we want to extract.

Inspecting Redfin Result page

From the above picture, here are all the DOM selectors the Web scraper will target to extract the information of each property.

Information DOM selector
Address .HomeCardContainer .homeAddressV2 .fullAddress
Price .HomeCardContainer .homecardV2Price span
Number of bed .HomeCardContainer .HomeStatsV2 .stats:first-child
Number of bath .HomeCardContainer .HomeStatsV2 .stats:nth-child(2)
Surface .HomeCardContainer .HomeStatsV2 .stats:last-child
Property link .HomeCardContainer a:has(div.link-and-anchor)
Contact phone number .HomeCardContainer a.large-phone-cta

Be careful when writing the selector because a misspelling will prevent the script from retrieving the correct value.

Note: A good method to avoid errors when building your selectors is to try them with jQuery first. In the browser’s console, type your selector like $(".HomeCardContainer .homeAddressV2 .fullAddress"). if it returns the correct DOM element, then you are good to go.

Showing how Redfin selectors dev console should returns

Step 4: Scrape Redfin’s Property Page

To access the data, we need to send a get() request to download the page’s HTML content.

However, after sending just a couple of requests, Redfin will identify our bot and block all requests coming from our IP address.

To overcome this challege, we’ll use Axios to send our requests through ScraperAPI. This scraping API will rotate our IP and headers automatically when needed, handle CAPTCHAs, etc., allowing us to bypass Redfin’s anti-bot detection.

The request needs the following query parameters:

  • The URL to scrape: it is the URL of the Redfin properties search page; you can copy it in the address bar of your browser.
  • The API Key: to authenticate against the Scraping API and perform the scraping.

Note: Create a free ScraperAPI account to get your unique API key.

Pro Tip: Scraping Localized Redfin Data

In the real estate industry, location is one of the most critical factors for property buyers or renters. Redfin operates in the USA and Canada, and using geo-targeting in our web scraper helps gather precise data for areas of these two countries.

With the ScraperAPI’s API, you can specify the country code from where the request must come from. In the HTTP request query parameter, you must set the key country_code with the value us to indicate the request comes from the United States.

Note: Check out the Scraping API documentation to view all supported country codes.

Edit the index.js file to add the code below that builds the HTTP request, sends it, receives the response, and prints it in the terminal.

	const axios = require('axios');

	const REDFIN_PAGE_URL = 'https://www.redfin.com/city/5155/CO/Denver/apartments-for-rent';
	const API_URL = 'https://api.scraperapi.com';
	const API_KEY = ''
	
	const webScraper = async () => {
		console.log('Fetching data with ScraperAPI...');
	
		const queryParams = new URLSearchParams({
				api_key: API_KEY,
				url: REDFIN_PAGE_URL,
				country_code: 'us'
		});
	
		try {
				const response = await axios.get(`${API_URL}?${queryParams.toString()}`);
	
				const html = response.data;
	
				console.log("HTML content", html);
		} catch (error) {
				console.log(error)
		}
	};
	
	void webScraper();

Step 5: Parse Redfin’s Property Listings

Now that we have the HTML content of the page, let’s parse it with Cheerio to easily navigate through the DOM and extract all the information we want.

Cheerio provides functions to load HTML text, then navigate through the structure to extract information using the DOM selectors.

The code below goes through each element, extracts the information, and returns an array containing all the properties.

	const cheerio = require('cheerio');

	const $ = cheerio.load(html);
	const propertyList = [];
	
	console.log('Extract information from the HTML...');
	
	$(".HomeCardContainer").each((_, el) => {
	   const price = $(el).find('.homecardV2Price span').text();
	   const beds = $(el).find('.HomeStatsV2 .stats:first-child').text();
	   const bath = $(el).find('.HomeStatsV2 .stats:nth-child(2)').text();
	   const space = $(el).find('.HomeStatsV2 .stats:last-child').text();
	   const address = $(el).find('.homeAddressV2 .fullAddress').text().substring(2);
	   const link = $(el).find('a:has(div.link-and-anchor)').attr('href');
	   const linkText = $(el).find('a:has(div.link-and-anchor)').text();
	   const contact = $(el).find('a.large-phone-cta').text();
	
	   if (!price) {
		   return
	   }
	
	   propertyList.push({
		   price,
		   address: address ?? linkText,
		   beds,
		   bath,
		   space,
		   link: link ? `https://www.redfin.com${link}` : null,
		   contact
	   });
	});
	
	console.log('JSON result:', propertyList);

Note: At this point, we’ve built the same scraper shown in the TL;DR of this article.

Run the code with the command node index.js, and appreciate the result.

Running the command node index on Redfin
Need More Than 3M API Credits per Month?

Monitoring real estate platforms can be challenging. Let our team of experts build a custom plan for your business to let you scrape property data at scale without the price tag.

Wrapping Up

Building a web scraper for Redfin can be done in the following steps:

  • Use Axios to send a request to the ScraperAPI standard API with the Redfin page to scrape, and download the rendered HTML content.
  • Parse the HTML with Cheerio to extract the data based on DOM selectors.
  • Format and transform the data retrieved to suit your needs.

The result is a list of relevant information about the properties to rent displayed on Redfin’s platform.

Here are a few ideas to go further with this Redfin Web scraper:

  • Retrieve the information about properties for sale
  • Make the scraper dynamic by allowing you to type the city directly.
  • Store the data in a database (RDBMS, JSON files, CSV files, etc…) to build historical data and make business decisions.
  • Use the Async Scraper service to scrape up to 10,000 URLs asynchronously.

To learn more, check out ScraperAPI’s documentation for Node.js.

Frequently Asked Questions

Redfin provides real estate data. You can scrape data about properties for sale or rent. For each property, you can get its history, amenities, features, property tax information, and neighborhood information.

You can also scrape data about real estate agents. For each agent, you can get professional contact, active listings, client reviews, and deal volume.

You should scrape Redfin data because it can have a positive impact on your business; here are a few things you can do with data collected:

  • Explore trends, pricing patterns, market fluctuations, and buyer/seller behaviors.
  • Identify the area where to invest money in real estate and marketing strategies.
  • Understand the demand for certain types of properties, amenities that attract buyers, or factors influencing property values. 
  • Build an application on top of these data, such as property comparators or investment tools.
  • Create visualizations or reports to share insights resulting from the analysis.

Redfin invests in various techniques to detect and prevent scraping activities to avoid excessive load on servers, as intensive scraping can impact the performance of their website. Redfin uses methods such as IP blocking, CAPTCHA challenges, rate limiting, or employing technology to identify and deter automated scraping bots.

Learn how ScraperAPI can help you scrape real estate platforms.

About the author

Eric Cabrel Tiogo

Eric Cabrel Tiogo

Eric Cabrel Tiogo is a software developer and tech mentor specializing in Java, Node.js, Typescript, GraphQL, AWS, Docker, and React. He runs a popular backend-focused blog, a developer newsletter, and actively contributes to OSS Cameroon, an open-source community. He's known for his CI/CD expertise with GitHub Actions and GitLab CI. Connect with him on Twitter and explore his work at blog.tericcabrel.com.

Table of Contents

Related Articles

Talk to an expert and learn how to build a scalable scraping solution.