For the complete documentation index, see llms.txt. This page is also available as Markdown.

旅游:酒店

抓取 Google Travel:酒店结果,并支持住客人数、日期和星级筛选。灵活的 API 集成,具备完整的参数选项。

google_travel_hotels 数据源旨在获取 Google Travel 服务的酒店搜索结果。

请求示例

在此示例中,我们发出请求以获取 2酒店可用性结果的第 nd 页 2 成年客人之间 2023-10-012023-10-1024-星级巴黎酒店,来自 google.com.

curl 'https://realtime.oxylabs.io/v1/queries' \\
--user 'USERNAME:PASSWORD' \\
-H 'Content-Type: application/json' \\
-d '{
        "source": "google_travel_hotels",
        "start_page": 2,
        "query": "hotels in Paris",
        "render": "html",
        "parse": true,
        "context": [
            {"key": "adults", "value": 2},
            {"key": "hotel_dates", "value": "2023-10-01,2023-10-10"},
            {"key": "hotel_classes", "value": [2, 3, 4]}
        ]
    }'
import requests
from pprint import pprint

# 结构化载荷。
payload = {
  "source": "google_travel_hotels",
  "query": "hotels in Paris",
  "start_page": 2,
  "render": "html",
  "parse": True,
  "context": [
    {
      "key": "adults",
      "value": 1
    },
    {
      "key": "hotel_dates",
      "value": "2023-10-01,2023-10-10"
    },
    {
      "key": "hotel_classes",
      "value": [2, 3, 4]
    }
  ]
}

# 获取响应。
response = requests.request(
    'POST',
    'https://realtime.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'),
    json=payload,
)

# Print prettified response to stdout.
pprint(response.json())

我们在示例中使用同步 Realtime 集成方法。如果您想使用 Proxy Endpoint 或异步 Push-Pull 集成,请参阅 集成方法 部分。

请求参数

通用

参数
描述
默认值

source

设置爬虫。使用 google_travel_hotels.

查询

请求的搜索词。 "query": "hotels" 将在给定的 geo_location.

"query": "hotels in <Location>" 将返回 <Location>.(例如 "query": "hotels in Paris" 将列出巴黎的酒店,无论 geo_location)

render

设置为时启用 JavaScript 渲染 html. 更多信息.

解析

设置为以下值时返回解析后的数据: true。更多信息请参阅 输出字典.

false

callback_url

回调端点的 URL。 更多信息.

user_agent_type

设备类型和浏览器。完整列表可在 此处.

desktop

- 必填参数

本地化

使搜索结果适配特定地理位置和语言。

参数
描述
默认值

geo_location

结果应适配的地理位置。 正确使用此参数对于获取正确数据极其重要。 请注意,此来源可接受有限数量的 geo_location 值 - 请查看 此部分 以查看 geo_location不会 产生准确结果。

-

locale

Accept-Language 标头值,它会更改您的 Google 搜索页面网页界面语言。 更多信息.

-

注意: "geo_location": "美国" 以及其他大范围位置都不受支持。请使用城市级 geo_location,例如, 西雅图,华盛顿,美国

分页

参数
描述
默认值

start_page

起始页码。

1

筛选

用于定制和细化搜索上下文的高级选项。

参数
描述
默认值

context:adults

成年客人数量

2

context:children

儿童客人数量

-

context: hotel_classes

按酒店星级筛选结果。您可以指定介于 25之间的一个或多个值。示例: [3,4]

-

context: hotel_dates

酒店入住日期,起止。示例: 2023-07-12,2023-07-13

-

所有 context 参数都应在 context 数组中,作为带有 键值对:

结构化数据

网页爬虫API 可以提取结果 HTML,或包含结果页面中各种元素结构化数据的 JSON 响应。

结构化 google_travel_hotels 输出(JSON)

输出字典

下表列出了我们解析的每个顶级元素,包括其描述和数据类型。

优惠数量和某些字段可能会因搜索词和住宿而异。

描述
类型

url

Google Travel 酒店搜索页面的 URL。

字符串

page

搜索结果的当前页码。

整数

last_visible_page

结果页中可见的最大页码。

整数

parse_status_code

解析任务的状态代码。了解更多 此处.

整数

results

包含解析后的酒店搜索结果的对象。

对象

results.offers

针对该查询返回的酒店优惠列表。包括 pos, 姓名, description, property_token, hotel_class, rating, deal, eco_certified, pricing, check_in_time, check_out_time, coordinates, amenities, images, nearby_places, website_url, details_url, reviews_url.

数组

results.overview

有关搜索结果的总体信息。包括 国家, language, total_results.

对象

results.pagination

有关当前结果页的详细信息。包括 current_from, current_to.

对象

创建时间

抓取任务创建时的时间戳。

时间戳

更新时间

抓取任务完成时的时间戳。

时间戳

任务ID

与抓取任务关联的任务ID。

字符串

状态码

抓取任务的状态码。了解更多 此处.

整数

最后更新于

这有帮助吗?