DEV Community

elliott maqy
elliott maqy

Posted on

Agoda vs Booking.com hotel prices: compare them with Python

"Is Agoda cheaper than Booking.com?" has no general answer, but it has a precise one for a given city and stay, and it takes about sixty lines of Python. This tutorial runs the same search on both sites, Rome, three nights a month from now, two adults, prices in euros, then does the part that usually goes wrong: recognising the same hotel on two sites that name it differently. The result is a table of matched hotels with an all-in price per night on each site, the gap in percent, and a count of which site wins. The data comes from two Apify Actors with the same output columns, the Agoda Hotels Scraper and the Booking.com Hotels Scraper, called through the official Python client.

What you need

  • An Apify account (the free plan is enough to try this) and its API token, from Apify Console → Settings → API & Integrations, exported as an environment variable: export APIFY_TOKEN=...
  • Python 3 and two packages:
pip install "apify-client>=3,<4" pandas
Enter fullscreen mode Exit fullscreen mode

Step 1: the same stay on both sites

Both Actors take the stay the same way: checkInDaysFromNow and nights for a stay relative to today (so the script works the day you read it), or checkIn and checkOut for fixed dates. Save this as agoda_vs_booking.py:

import os

import pandas as pd
from apify_client import ApifyClient

stay = {"checkInDaysFromNow": 30, "nights": 3, "adults": 2, "currency": "EUR"}

client = ApifyClient(os.environ["APIFY_TOKEN"])
booking_run = client.actor("myth84/booking-hotels-scraper").call(run_input={
    "location": "Rome, Italy", "destId": -126693, "propertyTypes": ["hotels"], "maxResults": 100, **stay,
})
agoda_run = client.actor("myth84/agoda-hotels-scraper").call(run_input={
    "location": "Rome", "sortBy": "RANKING", "maxResults": 150, **stay,
})
booking = pd.DataFrame(client.dataset(booking_run.default_dataset_id).iterate_items())
agoda = pd.DataFrame(client.dataset(agoda_run.default_dataset_id).iterate_items())

booking = booking[booking["priceTotal"].notna()].copy()
booking["allInPerNight"] = (booking["priceTotal"] + booking["taxesAndFees"].fillna(0)) / booking["nights"]
agoda = agoda[agoda["priceTotal"].notna()].copy()
agoda["allInPerNight"] = agoda["priceTotal"] / agoda["nights"]
print(len(booking), "priced hotels on Booking.com,", len(agoda), "on Agoda")
Enter fullscreen mode Exit fullscreen mode

The inputs come from public tasks: "Cheapest stays in Rome next month" on Booking.com (its destId, the dest_id of a Booking.com search URL for Rome) and "Hotels in Rome under the best guest scores" on Agoda. The orders changed on purpose. Booking.com keeps hotels only (propertyTypes) in its default top-picks order instead of the cheapest first, and Agoda uses its own ranking (RANKING, which varies a little between requests) instead of the best scores first: comparing the cheapest properties of one site with the best-rated of the other would match almost nothing. Agoda gets more rows because it lists many more properties per city; more rows on either side raise the number of matches.

The all-in price per night is the line to compare, and the two sites build it differently:

  • Booking.com: priceTotal is the total of the stay before the charges Booking.com lists as excluded (city tax, VAT, service charges), which are in taxesAndFees. The all-in total is the sum of both.
  • Agoda: with the default priceView (inclusive), priceTotal already includes taxes and fees; taxesAndFees gives their amount.

Properties without a price for the stay (sold out, for instance) are set aside.

Step 2: recognise the same hotel

The two sites have their own ids, so platformListingId does not join them, and names vary: the same place can be "Hotel X Roma" on one side and "X Hotel" on the other, with accents or not. Two clues together are reliable: a similar name once the noise words are removed, and a position within a couple of hundred metres. Both Actors return latitude and longitude. Add this to the script:

import math
import re
import unicodedata
from difflib import SequenceMatcher

NOISE = {"hotel", "hotels", "rome", "roma", "the", "and", "by", "di", "de", "del", "la", "il"}


def name_key(title):
    text = unicodedata.normalize("NFKD", title).encode("ascii", "ignore").decode().lower()
    return " ".join(word for word in re.findall(r"[a-z0-9]+", text) if word not in NOISE)


def metres(lat1, lon1, lat2, lon2):
    x = math.radians(lon2 - lon1) * math.cos(math.radians((lat1 + lat2) / 2))
    return 6_371_000 * math.hypot(x, math.radians(lat2 - lat1))


booking = booking.dropna(subset=["latitude", "longitude"])
agoda = agoda.dropna(subset=["latitude", "longitude"])
booking["nameKey"] = booking["title"].map(name_key)
agoda["nameKey"] = agoda["title"].map(name_key)

matches = []
for b in booking.itertuples():
    best, best_score = None, 0.0
    for a in agoda.itertuples():
        if metres(b.latitude, b.longitude, a.latitude, a.longitude) > 250:
            continue
        score = 1.0 if a.nameKey == b.nameKey else SequenceMatcher(None, a.nameKey, b.nameKey).ratio()
        if score > best_score:
            best, best_score = a, score
    if best is not None and best_score >= 0.8:
        matches.append({
            "hotel": b.title, "agodaName": best.title, "stars": b.starRating, "nameScore": round(best_score, 2),
            "booking": round(b.allInPerNight, 2), "agoda": round(best.allInPerNight, 2),
        })
Enter fullscreen mode Exit fullscreen mode

name_key removes accents, punctuation and the words every hotel in the city shares, then compares what is left. SequenceMatcher gives a similarity between 0 and 1; 0.8 within 250 metres keeps the obvious pairs and the small spelling differences. The distance test does most of the work for chains: two hotels of the same brand three kilometres apart never match. The agodaName and nameScore columns are there so you can check the pairs by eye; sort by nameScore and read the lowest ones first.

Step 3: which site is cheaper?

table = pd.DataFrame(matches)
table["gapPercent"] = (100 * (table.agoda - table.booking) / table.booking).round(1)
table["cheaper"] = "same (within 1 %)"
table.loc[table["gapPercent"] < -1, "cheaper"] = "agoda"
table.loc[table["gapPercent"] > 1, "cheaper"] = "booking"

print(f"{len(table)} hotels found on both sites")
print(table["cheaper"].value_counts())
print("Median gap by stars (negative: Agoda cheaper):")
print(table.groupby("stars")["gapPercent"].median())
print(table.sort_values("gapPercent").head(10))
table.to_csv("rome-agoda-vs-booking.csv", index=False)
Enter fullscreen mode Exit fullscreen mode

gapPercent is Agoda's all-in price per night compared with Booking.com's for the same hotel: −8 means Agoda is 8 % cheaper, +5 that Booking.com is. Differences under 1 % are counted as a tie, which is mostly rounding. The table by stars answers a narrower question that is often more useful: one site can be cheaper for budget hotels and the other for 4- and 5-star ones. The CSV keeps every pair with both names, for a spreadsheet or a second look.

Honest limits of the comparison

  • The match is partial. Each site returns its own selection in its own order, so only part of the hotels appear on both sides; how many depends on the city and on maxResults. A median over a few dozen matched hotels is a reasonable signal, not a market study.
  • Matching makes mistakes. A renamed hotel, or two hotels sharing a building, can be missed or paired wrongly. Raise the threshold to 0.9 for fewer false pairs, lower it for more pairs, and check the lowest nameScore rows.
  • Taxes are counted by each site. A local tax paid at the hotel, such as a city tax, can be in one site's figure and not the other's. Compare taxesAndFees on both sides before concluding that one site is cheaper.
  • One price per property: the cheapest offer of the search card for two adults in one room, not the same room type or the same cancellation terms on both sites.
  • Visitor prices, without an account or member discounts, in the chosen currency.
  • No personal data. Property facts, average scores and review counts; nothing about guests or reviewers.

Without code, and more cities

Each input is also a public task in Apify Console. Open "Hotels in Rome under the best guest scores" (Agoda) and "Cheapest stays in Rome next month" (Booking.com), align the stay, save both as your own tasks and schedule them at the same hour; the Output tabs export CSV with the same column names. For several cities, both Actors take a locations list with the same stay for every destination (["Paris", "Rome", "Barcelona"] on Agoda, ["Paris, France", "Rome, Italy", "Barcelona, Spain"] on Booking.com, as in the public tasks "Compare hotel prices in Paris, Rome and Barcelona"); run the matching per searchLocation.

Pricing is pay-per-event on both Actors, a fixed price per property saved: $2.00 per 1,000 on Agoda and $2.50 per 1,000 on Booking.com on Apify's Free plan, down to $1.29 and $1.69 on the higher plans. This comparison of 150 + 100 properties costs about $0.55. Use the data for analysis, respect the platforms' terms and local law, and do not republish listings.

Disclosure: I build these Actors and may earn a commission if you sign up to Apify through these links.

Top comments (0)