├── code examples ├── trivago_curl.sh ├── trivago_python.py ├── trivago_nodejs.js ├── trivago_php.php ├── trivago_golang.go ├── trivago_csharp.cs └── trivago_java.java └── README.md /code examples/trivago_curl.sh: -------------------------------------------------------------------------------- 1 | curl --user user:pass \ 2 | 'https://realtime.oxylabs.io/v1/queries' \ 3 | -H "Content-Type: application/json" \ 4 | -d '{"source": "universal", "url": "https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago"}' -------------------------------------------------------------------------------- /code examples/trivago_python.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from pprint import pprint 3 | 4 | # Structure payload. 5 | payload = { 6 | 'source': 'universal', 7 | 'url': 'https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago' 8 | } 9 | 10 | # Get response. 11 | response = requests.request( 12 | 'POST', 13 | 'https://realtime.oxylabs.io/v1/queries', 14 | auth=('user', 'pass1'), 15 | json=payload, 16 | ) 17 | 18 | # Instead of response with job status and results url, this will return the 19 | # JSON response with the result. 20 | pprint(response.json()) -------------------------------------------------------------------------------- /code examples/trivago_nodejs.js: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | 3 | const username = 'YOUR_USERNAME'; 4 | const password = 'YOUR_PASSWORD'; 5 | const body = { 6 | 'source': 'universal', 7 | 'url': 'https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago'}; 8 | 9 | const response = await fetch('https://realtime.oxylabs.io/v1/queries', { 10 | method: 'post', 11 | body: JSON.stringify(body), 12 | headers: { 13 | 'Content-Type': 'application/json', 14 | 'Authorization': 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'), 15 | } 16 | }); 17 | 18 | console.log(await response.json()); -------------------------------------------------------------------------------- /code examples/trivago_php.php: -------------------------------------------------------------------------------- 1 | 'universal', 5 | 'url' => 'https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago']; 6 | 7 | $ch = curl_init(); 8 | 9 | curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries"); 10 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 11 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 12 | curl_setopt($ch, CURLOPT_POST, 1); 13 | curl_setopt($ch, CURLOPT_USERPWD, "user" . ":" . "pass1"); 14 | 15 | $headers = array(); 16 | $headers[] = "Content-Type: application/json"; 17 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 18 | 19 | $result = curl_exec($ch); 20 | echo $result; 21 | 22 | if (curl_errno($ch)) { 23 | echo 'Error:' . curl_error($ch); 24 | } 25 | curl_close ($ch); 26 | ?> -------------------------------------------------------------------------------- /code examples/trivago_golang.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | ) 10 | 11 | func main() { 12 | const Username = "YOUR_USERNAME" 13 | const Password = "YOUR_PASSWORD" 14 | 15 | payload := map[string]string{ 16 | "source": "universal", 17 | "url": "https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago", 18 | } 19 | 20 | jsonValue, _ := json.Marshal(payload) 21 | 22 | client := &http.Client{} 23 | request, _ := http.NewRequest("POST", 24 | "https://realtime.oxylabs.io/v1/queries", 25 | bytes.NewBuffer(jsonValue), 26 | ) 27 | 28 | request.SetBasicAuth(Username, Password) 29 | response, _ := client.Do(request) 30 | 31 | responseText, _ := ioutil.ReadAll(response.Body) 32 | fmt.Println(string(responseText)) 33 | } -------------------------------------------------------------------------------- /code examples/trivago_csharp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Net.Http.Json; 5 | using System.Threading.Tasks; 6 | 7 | namespace OxyApi 8 | { 9 | class Program 10 | { 11 | static async Task Main() 12 | { 13 | const string Username = "YOUR_USERNAME"; 14 | const string Password = "YOUR_PASSWORD"; 15 | 16 | var parameters = new Dictionary() 17 | { 18 | { "source", "universal" }, 19 | { "url", "https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago"}, 20 | } 21 | 22 | 23 | var client = new HttpClient(); 24 | 25 | Uri baseUri = new Uri("https://realtime.oxylabs.io"); 26 | client.BaseAddress = baseUri; 27 | 28 | var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries"); 29 | requestMessage.Content = JsonContent.Create(parameters); 30 | 31 | var authenticationString = $"{Username}:{Password}"; 32 | var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString)); 33 | requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString); 34 | 35 | var response = await client.SendAsync(requestMessage); 36 | var contents = await response.Content.ReadAsStringAsync(); 37 | 38 | Console.WriteLine(contents); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /code examples/trivago_java.java: -------------------------------------------------------------------------------- 1 | import okhttp3.*; 2 | import org.json.JSONObject; 3 | 4 | public class Main implements Runnable { 5 | private static final String AUTHORIZATION_HEADER = "Authorization"; 6 | public static final String USERNAME = "YOUR_USERNAME"; 7 | public static final String PASSWORD = "YOUR_PASSWORD"; 8 | 9 | public void run() { 10 | JSONObject jsonObject = new JSONObject(); 11 | jsonObject.put("source", "universal"); 12 | jsonObject.put("url", "https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago"); 13 | 14 | Authenticator authenticator = (route, response) -> { 15 | String credential = Credentials.basic(USERNAME, PASSWORD); 16 | 17 | return response 18 | .request() 19 | .newBuilder() 20 | .header(AUTHORIZATION_HEADER, credential) 21 | .build(); 22 | }; 23 | 24 | var client = new OkHttpClient.Builder() 25 | .authenticator(authenticator) 26 | .build(); 27 | 28 | var mediaType = MediaType.parse("application/json; charset=utf-8"); 29 | var body = RequestBody.create(jsonObject.toString(), mediaType); 30 | var request = new Request.Builder() 31 | .url("https://realtime.oxylabs.io/v1/queries") 32 | .post(body) 33 | .build(); 34 | 35 | try (var response = client.newCall(request).execute()) { 36 | assert response.body() != null; 37 | System.out.println(response.body().string()); 38 | } catch (Exception exception) { 39 | System.out.println("Error: " + exception.getMessage()); 40 | } 41 | 42 | System.exit(0); 43 | } 44 | 45 | public static void main(String[] args) { 46 | new Thread(new Main()).start(); 47 | } 48 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Trivago Scraper API 2 | 3 | [![Oxylabs promo code](https://raw.githubusercontent.com/oxylabs/product-integrations/refs/heads/master/Affiliate-Universal-1090x275.png)](https://oxylabs.io/pages/gitoxy?utm_source=877&utm_medium=affiliate&groupid=877&utm_content=trivago-scraper-github&transaction_id=102f49063ab94276ae8f116d224b67) 4 | [![](https://dcbadge.limes.pink/api/server/Pds3gBmKMH?style=for-the-badge&theme=discord)](https://discord.gg/Pds3gBmKMH) [![YouTube](https://img.shields.io/badge/YouTube-Oxylabs-red?style=for-the-badge&logo=youtube&logoColor=white)](https://www.youtube.com/@oxylabs) 5 | 6 | Oxylabs’ [Trivago Scraper](https://oxylabs.io/products/scraper-api/web/trivago?utm_source=github&utm_medium=repositories&utm_campaign=product) is a data gathering solution allowing you to extract real-time information from an Trivago website effortlessly. This brief guide explains how an Trivago Scraper works and provides code examples to understand better how you can use it hassle-free. 7 | 8 | ### How it works 9 | 10 | You can get Trivago results by providing your own URLs to our service. We can return the HTML for any Trivago page you like. 11 | 12 | #### Python code example 13 | 14 | The example below illustrates how you can get HTML of Trivago page. 15 | 16 | ```python 17 | import requests 18 | from pprint import pprint 19 | 20 | # Structure payload. 21 | payload = { 22 | 'source': 'universal', 23 | 'url': 'https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago' 24 | } 25 | 26 | # Get response. 27 | response = requests.request( 28 | 'POST', 29 | 'https://realtime.oxylabs.io/v1/queries', 30 | auth=('user', 'pass1'), 31 | json=payload, 32 | ) 33 | 34 | # Instead of response with job status and results url, this will return the 35 | # JSON response with the result. 36 | pprint(response.json()) 37 | ``` 38 | Find code examples for other programming languages [**here**](https://github.com/oxylabs/trivago-scraper/tree/main/code%20examples) 39 | 40 | #### Output Example 41 | ```json 42 | { 43 | "results": [ 44 | { 45 | "content": "", 46 | "created_at": "2023-12-18 11:07:45", 47 | "updated_at": "2023-12-18 11:07:47", 48 | "page": 1, 49 | "url": "https://www.trivago.com/en-us/odr/hotels-chicago-illinois?search=200-14411&_gl=1*1u91udd*_up*mq..&gclid=trivago", 50 | "job_id": "7142470490890738689", 51 | "status_code": 200 52 | } 53 | ] 54 | } 55 | ``` 56 | With our Trivago Scraper, you can seamlessly extract public data from any Trivago web page. Gather essential hotel details like location, ratings, amenities, or guest reviews, to understand the hospitality industry and stay ahead in your business. If you need any assistance, our support team is just a live chat or an email away at hello@oxylabs.io. 57 | --------------------------------------------------------------------------------