### Node.js Proxy Setup Source: https://help.decodo.com/docs/code-integration This Node.js example shows how to configure an HTTP proxy with authentication using the 'axios' library. Make sure 'axios' is installed. ```javascript const axios = require("axios"); const url = "http://ip.decodo.com/json"; const resp = axios.get(url, { proxy: { host: 'gate.decodo.com', port: 7000, auth: { username: 'username', password: 'password' } } }). then(resp => { console.log(resp.data); }); ``` -------------------------------- ### Test Proxy with GO Source: https://help.decodo.com/docs/residential-proxy-quick-start This GO example shows how to test your proxy setup and confirm the IP address. ```go package main import ( "fmt" "io/ioutil" "net/http" "net/url" ) func main() { proxyUrl, _ := url.Parse("http://username:password@residential.proxy.decodo.com:8080") client := &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyURL(proxyUrl), }, } resp, err := client.Get("https://api.decodo.com/json/") if err != nil { fmt.Println("Error:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Go Proxy Setup Source: https://help.decodo.com/docs/code-integration This Go example shows how to configure an HTTP proxy with authentication using the standard 'net/http' package. It includes JSON decoding of the response. ```go package main import ( "encoding/json" "fmt" "log" "net/http" "net/url" ) const resourceUrl = "http://ip.decodo.com/json" proxyHost = "gate.decodo.com:7000" username = "username" password = "password" ) func main() { proxyUrl := &url.URL{ Scheme: "http", User: url.UserPassword(username, password), Host: proxyHost, } client := http.Client{ Transport: &http.Transport{ Proxy: http.ProxyURL(proxyUrl), }, } resp, err := client.Get(resourceUrl) if err != nil { log.Fatal(err) } defer resp.Body.Close() var body map[string]interface{} if err = json.NewDecoder(resp.Body).Decode(&body); err != nil { log.Fatal(err) } fmt.Println(body) } ``` -------------------------------- ### C# Proxy Setup Source: https://help.decodo.com/docs/code-integration This C# example demonstrates setting up an HTTP proxy with authentication using HttpClient. It includes asynchronous operations and basic error handling. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Task t = new Task(DownloadPageAsync); t.Start(); Console.ReadLine(); } static async void DownloadPageAsync() { string page = "http://ip.decodo.com/json"; var proxy = new WebProxy("gate.decodo.com:7000") { UseDefaultCredentials = false, Credentials = new NetworkCredential( userName: "username", password: "password") }; var httpClientHandler = new HttpClientHandler() { Proxy = proxy, }; var client = new HttpClient(handler: httpClientHandler, disposeHandler: true); var response = await client.GetAsync(page); using (HttpContent content = response.Content) { string result = await content.ReadAsStringAsync(); Console.WriteLine(result); Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } } ``` -------------------------------- ### Java Proxy Setup Source: https://help.decodo.com/docs/code-integration Example of setting up an HTTP proxy with authentication in Java. This code uses standard Java networking libraries. ```java import java.net.*; import java.io.*; import java.util.Scanner; public class ProxyTest { public static void main(String[] args) throws Exception { InetSocketAddress proxyAddress = new InetSocketAddress("gate.decodo.com", 7000); // Set proxy IP/port. Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); URL url = new URL("http://ip.decodo.com"); //enter target URL Authenticator authenticator = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication("username","password".toCharArray())); //enter credentials } }; Authenticator.setDefault(authenticator); URLConnection urlConnection = url.openConnection(proxy); //Scanner to view output Scanner scanner = new Scanner(urlConnection.getInputStream()); System.out.println(scanner.next()); scanner.close(); } } ``` -------------------------------- ### Ruby Proxy Setup Source: https://help.decodo.com/docs/code-integration Configure an HTTP proxy with authentication in Ruby using the 'net/http' library. This example shows how to set proxy host, port, and credentials. ```ruby require "uri" require 'net/http' proxy_host = 'gate.decodo.com' proxy_port = 7000 proxy_user = 'username' proxy_pass = 'password' uri = URI.parse('http://ip.decodo.com/json') proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass) req = Net::HTTP::Get.new(uri.path) result = proxy.start(uri.host, uri.port) do |http| http.request(req) end puts result.body ``` -------------------------------- ### Python Proxy Setup Source: https://help.decodo.com/docs/code-integration Use this snippet to set up an HTTP proxy with authentication in Python using the requests library. Ensure the 'requests' library is installed. ```python import requests url = 'http://ip.decodo.com/json' username = 'username' password = 'password' proxy = f'http://{username}:{password}@gate.decodo.com:7000' response = requests.get(url, proxies={'http': proxy, 'https': proxy}) print(response.text) ``` -------------------------------- ### Go Request Example Source: https://help.decodo.com/docs/web-scraping-api-google-lens-deprecated This Go snippet demonstrates how to make an HTTP GET request to the Google Lens API using the standard 'net/http' package. This is a fundamental way to handle HTTP in Go. ```go package main import ( "fmt" "io/ioutil" "net/http" ) func main() { url := "YOUR_API_ENDPOINT?q=your query&api_key=YOUR_API_KEY" resp, err := http.Get(url) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Request Google Travel Hotels Data Source: https://help.decodo.com/docs/web-scraping-api-google-travel-hotels-deprecated Use these examples to send a POST request to the scraping API. Ensure the authorization token is updated before execution. ```shellscript # update 'TOKEN VALUE' with your authorization token curl --request 'POST' \ --url 'https://scraper-api.decodo.com/v2/scrape' \ --header 'Accept: application/json' \ --header 'Authorization: Basic TOKEN VALUE' \ --header 'Content-Type: application/json' \ --data ' { "target": "google_travel_hotels", "query": "trivago", "page_from": "1", "stars": [4,5], "adults": 2 } ' ``` ```javascript const scrape = async() => { const response = await fetch("https://scraper-api.decodo.com/v2/scrape", { method: "POST", body: JSON.stringify({ "target": "google_travel_hotels", "query": "trivago", "page_from": "1", "stars": [4,5], "adults": 2 }), headers: { "Content-Type": "application/json", "Authorization": "Basic TOKEN VALUE" // update with your authorization token }, }).catch(error => console.log(error)); console.log(await response.json()) } scrape() ``` ```python import requests url = "https://scraper-api.decodo.com/v2/scrape" payload = { "target": "google_travel_hotels", "query": "trivago", "page_from": "1", "stars": [4,5], "adults": 2 } headers = { "accept": "application/json", "content-type": "application/json", "authorization": "Basic TOKEN VALUE" # update with your authorization token } response = requests.post(url, json=payload, headers=headers) print(response.text) ``` -------------------------------- ### Google Travel Hotels API JSON Response Source: https://help.decodo.com/docs/web-scraping-api-google-travel-hotels-deprecated Example of the JSON structure returned by the API, containing raw HTML content. ```json { "results": [ { "content":"