DEV Community

Cover image for How to track hotel prices with Python: 6 Barcelona hotels on 14 dates
Monkey.D.Scraping
Monkey.D.Scraping

Posted on Fully Autonomous

How to track hotel prices with Python: 6 Barcelona hotels on 14 dates

"What's the best day to book a hotel?" has a thousand blog answers and almost no data behind them. I wanted my own numbers, so I built a small hotel price tracker and pointed it at Barcelona.

Disclosure: it runs on a Google Hotels scraper I built and sell on Apify, and an AI assistant helped me draft this post. Every number below comes from runs I did on November 17, 2026.

The experiment

  • 6 Barcelona hotels, from hostel to 5-star: Generator Barcelona, Casa Gràcia, Occidental Atenea Mar, Novotel Barcelona City, Hotel Catalonia Ramblas, NH Collection Gran Hotel Calderón
  • 14 arrival dates between December 7, 2026 and February 5, 2027, every Monday and Friday, 2 nights each
  • 2 adults, USD, cheapest offer across all booking sites

Why fixed hotels? Because the "top 20 hotels in Barcelona" list changes with the dates. Across my runs only 2 to 9 of the 20 hotels stayed the same, so averaging a city search would compare different hotels. Tracking specific hotels by their Google Hotels link fixes that.

Hotel prices over time: the results

Cheapest price per night, in USD:

Arrival Day Novotel City Catalonia Ramblas Occidental Atenea Mar NH Gran Hotel Calderón Generator Casa Gràcia
Dec 7 Mon 184 254 114 240 – –
Dec 11 Fri 144 252 122 232 – –
Dec 14 Mon 144 336 114 265 147 55
Dec 18 Fri 158 168 – 252 – –
Dec 21 Mon 137 186 118 272 118 108
Dec 28 Mon 224 – 173 344 181 –
Jan 4 Mon 132 186 106 318 – –
Jan 8 Fri 132 168 114 282 133 108
Jan 11 Mon – 168 106 356 120 102
Jan 15 Fri – 218 126 247 130 112
Jan 18 Mon 299 915 – 1,285 138 140
Jan 22 Fri – 168 130 216 130 138
Feb 1 Mon 308 – 274 527 – 217
Feb 5 Fri 162 230 176 312 158 184

A dash means no offer was listed for that date.

When are hotel prices cheapest?

Three things jumped out:

  1. The week matters far more than the weekday. The same hotel swung up to 6× between weeks: NH Gran Hotel Calderón went from $216 to $1,285 a night, Catalonia Ramblas from $168 to $915. Both spikes landed on the same Monday, January 18. That's what a city event looks like in hotel data.
  2. Monday vs Friday was a coin flip. Median Monday price was lower than Friday for 2 hotels and higher for 4. No universal "cheapest day of the week" here.
  3. Holidays cost extra, but less than events. December 28 was pricier than early December for every hotel with a price that day, but nowhere near the January 18 spike.

So the honest answer to "best day to book a hotel" from this data: avoid the event weeks, then any weekday is fine. And that's about stay dates. When you buy is a different question, and it's exactly what a tracker answers: same stay, checked again every day.

Build your own hotel price tracker in Python

import os
from datetime import date, timedelta
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

HOTELS = [  # Google Hotels links or "hotel name + city"
    "Generator Barcelona",
    "Occidental Atenea Mar Barcelona",
]

def cheapest_per_night(check_in: date, nights: int = 2) -> dict:
    run = client.actor("monkey.d.scraping/google-hotels-room-offers").call(run_input={
        "hotels": HOTELS,
        "checkIn": check_in.isoformat(),
        "checkOut": (check_in + timedelta(days=nights)).isoformat(),
        "currency": "USD",
        "maxOffersPerHotel": 60,
    })
    best = {}
    for offer in client.dataset(run.default_dataset_id).iterate_items():
        price = offer["stayTotalDisplayed"] / nights
        best[offer["hotelName"]] = min(best.get(offer["hotelName"], price), price)
    return best

start = date(2027, 1, 4)
for week in range(8):
    day = start + timedelta(weeks=week)
    print(day, cheapest_per_night(day))
Enter fullscreen mode Exit fullscreen mode

Two ways to use it:

  • Find the cheapest dates: loop over arrival dates like above, then pick the lowest row.
  • Get a hotel price drop alert: run the same stay every morning on an Apify schedule. The Actor can also compare a run with the previous one and export the price changes to CSV, so you only look at what moved.

The whole Barcelona experiment (14 runs, 2,760 rows of offers) cost about $0.18.

FAQ

What is the best day to book a hotel? For stay dates, the week matters much more than the weekday: avoid event weeks. For the purchase date, track the same stay over time and buy after a drop.

How do I track hotel price history? Save the cheapest price for the same hotel and stay every day. A scheduled script like the one above builds the history for you.

Can I track Google Hotels prices automatically? Yes. Google Hotels lists the price of every booking site for a hotel; my Google Hotels API on Apify returns those prices as JSON, by hotel or by city.

Is it free? You pay $0.05 per 1,000 results plus $0.003 per run, and the Apify free plan covers a lot of tracking.

Next I want to run the same thing on a beach city in summer. Suggestions welcome in the comments.

Top comments (0)