Erik
Erik

Reputation: 59

RapidAPI: How can I find hotel_id in booking.com?

I am using API from RapidAPI for booking.com. I would like to get reviews of a hotel but I do not know how I can find hotel_id (required parameter) for a particular hotel?

import requests

url = "https://booking-com.p.rapidapi.com/v1/hotels/reviews"

querystring = {"hotel_id":"1676161","locale":"en-gb","sort_type":"SORT_MOST_RELEVANT","customer_type":"solo_traveller,review_category_group_of_friends","language_filter":"en-gb,de,fr"}

headers = {
    'x-rapidapi-host': "booking-com.p.rapidapi.com",
    'x-rapidapi-key': "1bed4aac31mshcd4d969233d7d7dp129f0bjsn58eea903e6c2"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

Upvotes: 1

Views: 1553

Answers (2)

Dmitrii Bykov
Dmitrii Bykov

Reputation: 55

I'll give you two methods: one is manual, and the other involves using code in Python. Understanding the first method will help you realize how the second one works.

Manual

  1. Open the hotel page on booking.com where you wish to find the hotel_id.
  2. Right-click on the page and select Inspect to open the Chrome Developer Tools.
  3. Navigate to the Console tab within the Developer Tools.
  4. Enter the following JavaScript command and press Enter:
document.querySelector('input[name="hotel_id"]').value

This command looks for an input element with the name attribute set to hotel_id and retrieves its value, which corresponds to the hotel's ID.

Python

Prerequisites:

Ensure you have requests and beautifulsoup4 installed in your Python environment. If not, you can install them using pip:

pip install requests beautifulsoup4

Python Code:

import requests
from bs4 import BeautifulSoup

# Replace 'YOUR_HOTEL_PAGE_URL' with the actual URL of the hotel page on booking.com
url = 'YOUR_HOTEL_PAGE_URL'

# Fetch the content of the hotel page
response = requests.get(url)

# Parse the HTML content of the page
soup = BeautifulSoup(response.text, 'html.parser')

# Find the input element with name='hotel_id' and get its value
hotel_id = soup.find('input', {'name': 'hotel_id'})['value']

print(f'The hotel_id is: {hotel_id}')

Upvotes: 0

user17775017
user17775017

Reputation:

You can find hotel_id using the below RapidAPI.

Get available hotels by the filter. Indicate the destination_id and dest_type -> use @Search locations endpoint, check-in and check-out date, number of adults and children. For possible filters use @Filters for search

import requests

url = "https://booking-com.p.rapidapi.com/v1/hotels/search"

querystring = {"room_number":"1","order_by":"popularity","filter_by_currency":"AED","checkout_date":"2022-07-02","checkin_date":"2022-07-01","units":"metric","adults_number":"2","dest_id":"-553173","dest_type":"city","locale":"en-gb","children_number":"2","children_ages":"5,0","page_number":"0","include_adjacency":"true","categories_filter_ids":"class::2,class::4,free_cancellation::1"}

headers = {
    'x-rapidapi-host': "booking-com.p.rapidapi.com",
    'x-rapidapi-key': "0195db92d0msh8afac0130adb2c4p1087e9jsn2aeab9e0aa0f"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

The result is like below.

"result": [
    {
      "id": "property_card_791664",
      "hotel_name": "Cheval Thorney Court at Hyde Park",
      "class_is_estimated": 0,
      "hotel_has_vb_boost": 0,
      "district": "Kensington and Chelsea",
      "cant_book": null,
      "distance_to_cc": "4.00",
      "mobile_discount_percentage": 0,
      "is_mobile_deal": 0,
      "is_free_cancellable": 0,
      "countrycode": "gb",
      "latitude": 51.5011118011927,
      "districts": "1545,29,44,333,2280",
      "city_name_en": "London",
      "min_total_price": 379.24,
      "hotel_id": 791664,
      ...

You can get hotel_id from the result.

Visit https://rapidapi.com/tipsters/api/booking-com/tutorials/booking-api-tutorial-1

Thanks.

Upvotes: 2

Related Questions