0

我正在为 booking.com 使用 RapidAPI 的 API。我想获得酒店的评论,但我不知道如何找到特定酒店的 hotel_id(必需参数)?

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)
4

1 回答 1

3

您可以使用以下 RapidAPI 找到 hotel_id。

通过过滤器获取可用酒店。指明destination_id 和dest_type -> 使用@Search 位置端点、入住和退房日期、成人和儿童人数。对于可能的过滤器,请使用 @Filters 进行搜索

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)

结果如下所示。

"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,
      ...

您可以从结果中获取 hotel_id。

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

谢谢。

于 2022-01-05T10:56:58.477 回答