跳到正文
DEV Community· huynhtanan·· 3 小時前AI 評分51

Google Hotels 如何用 Python 查詢指定日期房價及比較訂房網站價格

How to get Google Hotels prices for any dates with Python (and see which booking site is cheapest)

AI 導讀

huynhtanan 建立並在 Apify 發佈三款 Google Hotels 抓取工具,示範以 Python 查詢指定日期的酒店價格、比較訂房網站報價及搜尋特定酒店的低價日期。

正文

Google Hotels is one of the best places to compare hotel prices: for every hotel it shows the rate on Booking.com, Expedia, Agoda, Hotels.com, the hotel's own website and a dozen smaller sites, for the exact dates you pick. There is no official API for it, though.

I needed this data for a price-monitoring project, so I built three scrapers for it and published them on Apify. This post shows how to use them from Python. Disclosure: I'm the author of these scrapers, and they are paid per result. New Apify accounts get free monthly credit, which covers a few thousand hotels.

All code is in this repo: github.com/huynhtanan/google-hotels-api

Setup

pip install "apify-client>=3"
export APIFY_TOKEN=...   # free account -> Settings -> API & Integrations

1. Every hotel in a city, for your dates, under a budget

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

check_in = date.today() + timedelta(days=30)
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("zet46/google-hotels-scraper").call(run_input={
    "queries": ["Lisbon"],
    "checkIn": check_in.isoformat(),
    "checkOut": (check_in + timedelta(days=2)).isoformat(),
    "currency": "EUR",
    "maxHotelsPerQuery": 20,
    "maxPricePerNight": 200,
})
for h in client.dataset(run.default_dataset_id).iterate_items():
    print(h["name"], h["hotelClass"], h["pricePerNightText"], h["totalPrice"], h["rating"], h["reviewsCount"])

Real output (2 nights in November):

Brown's | Avenue Hotel                     5*   €171/night  total   378.16  rating 4.6 (282)
Dos Reis by The Beautique Hotels           4*   €104/night  total   235.54  rating 4.4 (423)
20-2 Lisbon Castle view apartment with Fre       €70/night  total   139.93  rating 5 (16)
Hotel Portugal - Portugal Boutique Hotel   4*   €128/night  total   285.90  rating 4.7 (1259)
Boutique Chiado Apartments & Suites        4*   €110/night  total   230.69  rating 4.6 (427)
Hotel Marquês de Pombal                    4*    €81/night  total   179.37  rating 4.4 (2460)
1908 Lisboa Hotel                          4*   €125/night  total   280.63  rating 4.7 (683)
Lisbon Wine House - Rooms & Suites         3*    €51/night  total   125.07  rating 3.7 (125)

Each hotel also comes with coordinates, check-in/out times, nearby places with travel times, photos, the hotel website, the rating distribution, and review topics: what guests mention, with positive and negative counts. For example, {"topic": "Location", "mentions": 342, "positive": 301, "negative": 16}.

Two details that bit me while building this:

  • Dates and currency are not URL parameters. Google Hotels encodes the search state in a protobuf blob in the ts query parameter, so ?checkin= is simply ignored. The scraper builds that blob for you.
  • Prices: pricePerNight is the nightly price including taxes. totalPrice is the whole stay including taxes and fees.

2. Which booking site is cheapest? (rate parity)

Set includeProviderPrices: true and each hotel gets the full list of booking sites, cheapest first, with direct booking links:

Hôtel CHEVALLIER  (20 booking sites, 38% spread)
   Hotels.com                      $64
   Expedia.com                     $66
   Travelocity.com                 $66
   Orbitz.com                      $66
   CheapTickets.com                $66
Hôtel Madame Rêve  (33 booking sites, 45% spread)
   Traveluro                      $536
   trivago DEALS                  $541
   Evendo                         $559
   Super.com                      $577
   Clicktrip.com                  $592
Glint Paris  (16 booking sites, 58% spread)
   Booking.com                     $81

The spreads are bigger than I expected: 38% for a small hotel, 58% for Glint Paris, where Booking.com was cheaper than the hotel's own website. If you work in hotel revenue management, this is a rate parity check. If you build travel apps, it's the "cheapest place to book" feature.

3. The cheapest nights to book a specific hotel

The price calendar scraper checks one hotel for every check-in date in a range:

run = client.actor("zet46/google-hotels-price-calendar").call(run_input={
    "hotels": ["Hilton Paris Opera"], "numberOfDates": 30, "nights": 1, "currency": "USD",
})
Hilton Paris Opera: 5 cheapest nights in the next 30 days
  2026-11-01 (Sun)  $314 on KAYAK.com
  2026-11-08 (Sun)  $314 on KAYAK.com
  2026-11-14 (Sat)  $314 on KAYAK.com
  2026-10-26 (Mon)  $315 on Expedia.com
  2026-11-02 (Mon)  $327 on KAYAK.com
Average: 477.89 | most expensive: 2026-10-24

The cheapest night was 34% below the 30-day average. That's useful for flexible travelers, and for anyone tracking how a competitor prices weekends versus weekdays.

4. Vacation rentals

Google Hotels also lists apartments and villas from Vrbo, Booking.com, Expedia, HomeToGo and others. The rentals scraper adds bedrooms, bathrooms, guests and amenities, plus filters (filtered-out rentals aren't charged):

LOVELY FLAT. GREAT LOCATION, CASTLE VIEWS AND Entire apartment   sleeps 4, 2 bd   $193/night  rating 4.82
Alfama River View | Balcony | Families | Fast Entire apartment   sleeps 4, 2 bd   $123/night  rating 4.78
WHome City View Penthouse Luxurious Living in Entire apartment   sleeps 8, 3 bd   $224/night  rating 4.75
Alecrim 3 Luxury Tailor Made Flat With a View Entire apartment   sleeps 4, 2 bd   $243/night  rating 4.79
2 Bedroom Apartment with Great Transport Link Entire apartment   sleeps 4, 2 bd    $65/night  rating 4

Bonus: give an AI agent live hotel prices

All three scrapers work through Apify's MCP server, so Claude, Cursor or any MCP client can call them:

{"mcpServers": {"apify": {"url": "https://mcp.apify.com?tools=zet46/google-hotels-scraper,zet46/google-hotels-price-calendar"}}}

Then ask "Find 4-star hotels in Lisbon under 150 EUR for 12-14 December and tell me which site is cheapest."

Cost

  • Hotels: $2 per 1,000.
  • Booking-site prices: +$2 per 1,000 hotels, only when you turn them on.
  • Price calendar: $1.50 per 1,000 date prices.

A 30-day calendar for one hotel costs about $0.05.

Code and examples: github.com/huynhtanan/google-hotels-api. Feedback and feature requests are welcome in the comments.

來源:DEV Community · dev.to