The google_travel_hotels data source is designed to retrieve Google Travel service's hotel search results.
To ensure optimal utilization of this service, include the "render": "html" parameter in your request.
Request samples
In this example, we make a request to retrieve the 2nd results page for hotel availability for 2 adult guests between 2023-10-01 and 2023-10-10 for 2 to 4-star hotels in Paris from google.com.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
namespace OxyApi
{
class Program
{
static async Task Main()
{
const string Username = "USERNAME";
const string Password = "PASSWORD";
var parameters = new {
source = "google_travel_hotels",
domain = "com",
start_page = 2,
query = "hotels in Paris",
render = "html",
context = new dynamic [] {
new { key = "adults", value = 2 },
new { key = "hotel_dates", value = "2023-10-01,2023-10-10" },
new { key = "hotel_classes", value = new int [] {2, 3, 4} }
}
};
var client = new HttpClient();
Uri baseUri = new Uri("https://realtime.oxylabs.io");
client.BaseAddress = baseUri;
var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries");
requestMessage.Content = JsonContent.Create(parameters);
var authenticationString = $"{Username}:{Password}";
var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString));
requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);
var response = await client.SendAsync(requestMessage);
var contents = await response.Content.ReadAsStringAsync();
Console.WriteLine(contents);
}
}
}
package org.example;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;
public class Main implements Runnable {
private static final String AUTHORIZATION_HEADER = "Authorization";
public static final String USERNAME = "USERNAME";
public static final String PASSWORD = "PASSWORD";
public void run() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("source", "google_travel_hotels");
jsonObject.put("domain", "com");
jsonObject.put("start_page", 2);
jsonObject.put("query", "hotels in Paris");
jsonObject.put("render", "html");
jsonObject.put("context", new JSONArray()
.put(new JSONObject().put("key", "adults").put("value", 2))
.put(new JSONObject().put("key", "hotel_dates").put("value", "2023-10-01,2023-10-10"))
.put(new JSONObject().put("key", "hotel_classes").put("value", new JSONArray().put(2).put(3).put(4)))
);
Authenticator authenticator = (route, response) -> {
String credential = Credentials.basic(USERNAME, PASSWORD);
return response
.request()
.newBuilder()
.header(AUTHORIZATION_HEADER, credential)
.build();
};
var client = new OkHttpClient.Builder()
.authenticator(authenticator)
.readTimeout(180, TimeUnit.SECONDS)
.build();
var mediaType = MediaType.parse("application/json; charset=utf-8");
var body = RequestBody.create(jsonObject.toString(), mediaType);
var request = new Request.Builder()
.url("https://realtime.oxylabs.io/v1/queries")
.post(body)
.build();
try (var response = client.newCall(request).execute()) {
if (response.body() != null) {
try (var responseBody = response.body()) {
System.out.println(responseBody.string());
}
}
} catch (Exception exception) {
System.out.println("Error: " + exception.getMessage());
}
System.exit(0);
}
public static void main(String[] args) {
new Thread(new Main()).start();
}
}
Basic setup and customization options for scraping Google Travel: Hotels results.
Parameter
Description
Default Value
source
Sets the scraper.
google_travel_hotels
query
UTF-encoded keyword.
"query": "hotels" will result in a list of hotels in a given geo_location.
"query": "hotels in <Location>" will result in a list of hotels for <Location>. For example, "query": "hotels in Paris" will list hotels in Paris, regardless of the given geo_location.
-
render
Enables JavaScript rendering when set to html. More info.
Device type and browser. The full list can be found here.
desktop
- mandatory parameter
Localization
Adapt search results to specific geographical locations, domains, and languages.
Parameter
Description
Default Value
geo_location
The geographical location that the result should be adapted for. Using this parameter correctly is extremely important to get the right data. Please note that this source can accept a limited number of geo_location values - please check this section to see geo_location values that don't yield accurate results.
-
domain
Domain localization for Google. The full list of available domains can be found here.
com
locale
Accept-Language header value which changes your Google search page web interface language. More info.
-
NOTE:"geo_location": "United States" and other wide-area locations are not supported. Use city-level geo_location, e.g., Seattle,Washington,United States
Pagination
Controls for managing the pagination.
Parameter
Description
Default Value
start_page
Starting page number.
1
Filtering
Advanced options for tailoring and refining the search context.
Parameter
Description
Default Value
context:adults
Number of adult guests
2
context:children
Number of children guests
-
context:
hotel_classes
Filter results by # of hotel stars. You may specify one or more values between 2 and 5. Example: [3,4]
-
context:
hotel_dates
Dates for staying at the hotel, from - to. Example: 2023-07-12,2023-07-13
-
Context parameters
All context parameters should be added to the context array as objects with key and value pairs, e.g.: