DEV Community

Anurag Kumar
Anurag Kumar

Posted on Edited on Originally published at apiserpent.com

How to Scrape Airbnb Listings with Python and Node

I run Serpent, the API used in the examples below.

To get Airbnb listings in Python or Node, send one GET request with a place, dates and a guest count, and read the JSON that comes back. Each answer holds up to 18 stays, each with a price, rating, badges and coordinates.

Short answer: For one look at one city, a browser and a spreadsheet are enough. Reading the search page with your own code works too, but the page is built for people using a browser, not for programs, and nothing promises it keeps its shape from one month to the next. For anything that runs on a schedule, feeds a product or covers many places, one API call is less code to own. Every snippet below is complete: change the key and the place, and run it.

The outputs printed under the snippets come from three saved answers: Munich and Porto recorded on 23 November 2026, and Barcelona recorded on 20 November 2026.

How do you get the stays with one request in Python?

Send a GET request to https://apiserpent.com/api/airbnb/search with your key in the X-API-Key header. Only location is required. Put your key in place of the placeholder, install requests, and run this. It searches Munich by its German name over two nights, and prints the place Airbnb understood and the first three stays with a price per night:

from datetime import date, timedelta

import requests

API_KEY = "sk_live_your_api_key"
URL = "https://apiserpent.com/api/airbnb/search"


def search_airbnb(location, checkin=None, checkout=None, **filters):
    """One GET request = one search. Leave both dates out for a flexible search."""
    params = {"location": location, **filters}
    if checkin and checkout:
        params["checkin"], params["checkout"] = checkin, checkout
    r = requests.get(URL, params=params, headers={"X-API-Key": API_KEY}, timeout=60)
    r.raise_for_status()
    return r.json()


if __name__ == "__main__":
    checkin = date.today() + timedelta(days=30)  # checkin and checkout cannot be in the past
    checkout = checkin + timedelta(days=2)
    data = search_airbnb("München", checkin.isoformat(), checkout.isoformat())

    if not data["listings"]:
        print("No stays came back for this search")
    else:
        nights = (checkout - checkin).days  # for a flexible search, use each stay's stay_nights instead
        print(f'{data["location"]}: {len(data["listings"])} stays, {data["checkin"]} to {data["checkout"]} ({nights} nights)')
        for stay in data["listings"][:3]:
            rating = stay["rating"] if stay["rating"] is not None else "none yet"
            title = (stay["title"] or "")[:32]
            if stay["price"] is None:
                print(f'{title:<32} price n/a, rating: {rating}')
            else:
                print(f'{title:<32} ${stay["price"]:>4} total, ${stay["price"] / (stay.get("stay_nights") or nights):6.2f} a night, rating: {rating}')
Enter fullscreen mode Exit fullscreen mode

The output, from the saved answer of 23 November 2026 (when you run it, the dates are 30 days from today):

Munich, Germany: 18 stays, 2027-01-07 to 2027-01-09 (2 nights)
Premier Inn München City Zentrum $ 196 total, $ 98.00 a night, rating: none yet
MIO by AMANO                     $ 251 total, $125.50 a night, rating: 4.77
B&B HOTEL München-Hbf            $ 161 total, $ 80.50 a night, rating: 4.76
Enter fullscreen mode Exit fullscreen mode

Three things are worth noticing. The location in the answer is the place that was searched, and here München came back as Munich, Germany. A dated search gives the price of the whole stay, so the code divides by the number of nights. And the first stay has no rating yet, which comes back as null, not zero.

Here is a trimmed excerpt of the same answer, with the photo link left out:

{
  "success": true,
  "location": "Munich, Germany",
  "checkin": "2027-01-07",
  "checkout": "2027-01-09",
  "listings": [
    {
      "id": "1781346526481241534",
      "url": "https://www.airbnb.com/rooms/1781346526481241534",
      "name": "Premier Inn München City Zentrum",
      "title": "Premier Inn München City Zentrum",
      "subtitle": "Hotel in Altstadt München",
      "latitude": 48.1354,
      "longitude": 11.5659,
      "price_text": "$196 for 2 nights",
      "price": 196,
      "price_original": null,
      "price_qualifier": "for 2 nights",
      "stay_checkin": "2027-01-07",
      "stay_checkout": "2027-01-09",
      "stay_nights": 2,
      "rating": null,
      "reviews_count": null,
      "badges": ["Featured hotel"]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

The code checks listings, not the HTTP status. A search with nothing to show comes back in the same shape with an empty list, so the reliable test is whether you got rows.

On a fixed set of 78 searches in 40 countries, the median call took 4.4 seconds and 9 in 10 finished within 5.8, so a 60-second timeout leaves plenty of room.

What can you ask for?

A search takes ten parameters. One is required and the other nine narrow the search.

Parameter What it takes What it does
location Text, up to 120 characters. Required The place, as you would type it on Airbnb, in any language: a city, neighbourhood, region or landmark. Add the country when a name is ambiguous, for example Lagos, Nigeria
checkin, checkout Dates as YYYY-MM-DD Neither can be in the past. Prices then cover the whole stay. Leave both out for a flexible search, where Airbnb picks a stay for each listing and the price covers that stay
adults 1 to 16, default 1 Number of adults
children 0 to 15, default 0 Number of children aged 2 to 12
pets 0 to 5, default 0 When set, only pet-friendly stays come back
room_type any, entire_home or private_room, default any The type of place
price_min, price_max Whole US dollars Lowest and highest price per night
min_bedrooms 1 to 50 Fewest bedrooms

Send the place name in the language you would normally use. München resolved to Munich, Germany, and in the 78-search check, names in other scripts such as 서울 resolved to Seoul, South Korea.

How do you filter by guests, bedrooms and budget in Node?

Node 18 and later includes fetch, so this needs no packages. Save it as filtered.mjs so top-level await works. It asks for a week in Barcelona for two adults, two children and a pet, in an entire home with at least two bedrooms, within a per-night budget, and then looks at what came back:

const API_KEY = "sk_live_your_api_key";
const ENDPOINT = "https://apiserpent.com/api/airbnb/search";

async function searchAirbnb(params) {
  const res = await fetch(`${ENDPOINT}?${new URLSearchParams(params)}`, {
    headers: { "X-API-Key": API_KEY },
    signal: AbortSignal.timeout(60_000),
  });
  if (res.ok === false) throw new Error(`HTTP ${res.status}`);
  return res.json();
}

// checkin and checkout cannot be in the past: a week, starting 30 days from today.
const day = (n) => new Date(Date.now() + n * 86_400_000).toISOString().slice(0, 10);
const nights = 7;

const data = await searchAirbnb({
  location: "Barcelona",
  checkin: day(30),
  checkout: day(30 + nights),
  adults: "2",
  children: "2",
  pets: "1",
  room_type: "entire_home",
  price_min: "500",
  price_max: "4000",
  min_bedrooms: "2",
});

if (data.listings.length === 0) {
  console.log("No stays came back for this search");
} else {
  // price is the total for the stay it covers; stay_nights is that stay's length (your dates for a dated search).
  // The nights of your search are used when stay_nights is null. A null price is skipped.
  const perNight = data.listings.filter((s) => s.price !== null).map((s) => s.price / (s.stay_nights ?? nights)).sort((a, b) => a - b);
  console.log(`${data.location}: ${data.listings.length} stays for ${nights} nights`);
  if (perNight.length > 0) console.log(`cheapest night $${perNight[0].toFixed(2)}, dearest $${perNight.at(-1).toFixed(2)}`);
  else console.log("cheapest night n/a: no stay had a price");
  // ids come back as strings. Many are longer than a JavaScript number can hold exactly.
  const long = data.listings.find((s) => Number(s.id) > Number.MAX_SAFE_INTEGER);
  if (long) {
    console.log(long.price_text ?? "n/a", "|", long.title);
    console.log("id as string:", long.id, "| as Number:", Number(long.id));
  }
}
Enter fullscreen mode Exit fullscreen mode

The output, from the saved answer of 20 November 2026:

Barcelona, Spain: 18 stays for 7 nights
cheapest night $516.71, dearest $1018.43
$3,917 for 7 nights | Condo in Eixample
id as string: 649666729910518567 | as Number: 649666729910518500
Enter fullscreen mode Exit fullscreen mode

Two details matter. The budget parameters are per night, while price in the answer is the total for the stay, so the code divides by each stay's stay_nights. And id is a string. The last line shows why: a JavaScript Number cannot hold 649666729910518567 exactly and prints 649666729910518500, so keep ids as text. MDN's page on Number.MAX_SAFE_INTEGER explains the limit.

What does each field in a listing mean?

Each stay in listings carries eighteen fields, in the order Airbnb shows the stays.

Field What it holds
id The listing id, as text
url The link to the stay
name The host's own name for the listing
title Airbnb's title: the type of place and the area, such as "Apartment in Munich"
subtitle The line under the title
latitude, longitude Where the stay is
price_text The price exactly as shown
price The amount in US dollars: the total for the stay it covers (your dates for a dated search, the stay Airbnb picked for a flexible one)
price_original The amount before a discount, when the stay shows one
price_qualifier What price covers, such as "for 3 nights"
stay_checkin, stay_checkout, stay_nights The stay that price covers. Null where Airbnb does not say
rating, reviews_count The star rating and the number of reviews; null for a stay with none yet
badges A list of badges such as Guest favorite, Superhost or Featured hotel
photo The cover photo link

For a flexible search the top-level dates come back as empty strings, so take the nights from each listing's stay_nights instead.

How do you handle empty fields?

Treat an empty field as information, not as a failure. Across the three saved answers, 54 listings in all, every listing had an id, link, name, title, subtitle, coordinates, price and photo. A rating and a review count were present on 49, a badge on 47, and a price before a discount on 16. The five listings without a rating are all in the Munich answer, and each is a hotel.

An empty rating is null, an empty price_original is null and an empty badges is an empty list, so test for those before you do arithmetic. This helper writes the stays to a CSV, with empty cells for the nulls, and keeps the id as text. Save the first Python snippet as one_call.py first, because this one imports it:

import csv

from one_call import search_airbnb

COLUMNS = ["id", "title", "price", "price_original", "price_qualifier", "rating", "reviews_count", "latitude", "longitude"]


def to_csv(data, path):
    """One row per stay. A null (no rating yet, no discount) becomes an empty cell, and the id stays text."""
    with open(path, "w", newline="") as f:
        w = csv.writer(f)
        w.writerow(COLUMNS)
        for stay in data["listings"]:
            w.writerow(["" if stay[c] is None else stay[c] for c in COLUMNS])


if __name__ == "__main__":
    to_csv(search_airbnb("Porto", adults=2), "porto.csv")
    lines = open("porto.csv").read().splitlines()
    print(len(lines) - 1, "rows")
    print(lines[0])
    print(lines[1])
    print(lines[8])
Enter fullscreen mode Exit fullscreen mode

It prints the row count, the header, the first stay in a flexible Porto search and the eighth, which has no price before a discount, so that cell is empty:

18 rows
id,title,price,price_original,price_qualifier,rating,reviews_count,latitude,longitude
598251653443045279,Apartment in Porto,128,183,for 2 nights,4.93,306,41.1503,-8.6082
53340395,Condo in Porto,192,,for 2 nights,4.99,319,41.1466,-8.6122
Enter fullscreen mode Exit fullscreen mode

Which route should you pick?

  • A one-off look at one city: a browser and a spreadsheet. Nothing here needs code.
  • A scheduled job or a pricing tool: one API call per search.
  • Many places and date ranges: the API, with a loop or a worker pool around the Python function above, and a check for an empty listings on every response.
  • A product where a person waits for the answer: the API, with the 60-second timeout above and a median of 4.4 seconds in mind.

Whichever route you take, read the site's terms and the rules where you work before you collect data.


The full version, with the field-fill chart, FAQ and sources, is on the original post on apiserpent.com.

Top comments (0)