Scrapingbypass Proxy Code Examples

Code examples are available in the Scrapingbypass Proxy dashboard:
https://console.scrapingbypass.com/#/proxy/account

Code Examples: Integrating ScrapingBypass Proxies

The following code snippets demonstrate how to integrate ScrapingBypass Rotating Proxies using standard Username:Password authentication across multiple programming languages.

Note on Proxy Host: * Use ge.scrapingbypass.com as the host.

  • Default Ports: 1288 for HTTP or 1288 for SOCKS5.
  • Ensure your network environment allows connections to the gateway (use Global Proxy/TUN mode if in Mainland China).

JavaScript (Axios)

const axios = require('axios');

const host = 'ge.scrapingbypass.com';
const port = 1288; 
const username = 'your_username';
const password = 'your_password';
const url = 'https://example.com/';

const config = {
    proxy: {
        protocol: 'http',
        host: host,
        port: port,
        auth: {
            username: username,
            password: password
        }
    }
};

axios.get(url, config)
    .then((response) => {
        console.log(response.data);
    })
    .catch((error) => {
        console.error(error);
    });

TypeScript (Axios)

import axios, { AxiosRequestConfig } from 'axios';

const host = 'ge.scrapingbypass.com';
const port = 1288;
const username = 'your_username';
const password = 'your_password';
const url = 'https://example.com/';

const config: AxiosRequestConfig = {
    proxy: {
        protocol: 'http',
        host: host,
        port: port,
        auth: {
            username: username,
            password: password
        }
    }
};

axios.get(url, config)
    .then((response) => {
        console.log(response.data);
    })
    .catch((error) => {
        console.error(error);
    });

Python (Requests)

import requests

host = 'ge.scrapingbypass.com'
port = 1288
username = 'your_username'
password = 'your_password'
url = 'https://example.com/'

# Note: Connect to the proxy gateway via HTTP
proxies = {
    'http': f'http://{username}:{password}@{host}:{port}',
    'https': f'http://{username}:{password}@{host}:{port}'
}

if __name__ == '__main__':
    try:
        resp = requests.get(url, proxies=proxies, timeout=30)
        print(resp.text)
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")

Python (Aiohttp)

import aiohttp
import asyncio

async def fetch(session):
    host = 'ge.scrapingbypass.com'
    port = 1288
    username = 'your_username'
    password = 'your_password'
    url = 'https://example.com/'
    proxy_url = f'http://{username}:{password}@{host}:{port}'

    async with session.get(url, proxy=proxy_url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        try:
            html = await fetch(session)
            print(html)
        except Exception as e:
            print(f"Error: {e}")

if __name__ == '__main__':
    asyncio.run(main())

Java (HttpURLConnection)

import java.net.*;
import java.io.*;

public class ProxyConnect {
  public static void main(String[] args) {
    final String authUser = "your_username";
    final String authPassword = "your_password";
    final String proxyHost = "ge.scrapingbypass.com";
    final int proxyPort = 1288;
    final String destURL = "https://example.com/";

    // Required to enable proxy authentication for modern JDKs
    System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
    System.setProperty("jdk.http.auth.proxying.disabledSchemes", "");

    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));

    Authenticator.setDefault(new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
        if (getRequestorType().equals(RequestorType.PROXY)) {
          return new PasswordAuthentication(authUser, authPassword.toCharArray());
        }
        return super.getPasswordAuthentication();
      }
    });

    try {
      URL url = new URL(destURL);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);

      try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        String line;
        while ((line = in.readLine()) != null) {
          System.out.println(line);
        }
      }
      connection.disconnect();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Go (Net/Http)

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
    "time"
)

func main() {
    host := "ge.scrapingbypass.com"
    port := "1288"
    username := "your_username"
    password := "your_password"
    targetUrl := "https://example.com/"

    proxyRawUrl := fmt.Sprintf("http://%s:%s@%s:%s", username, password, host, port)
    proxyUrl, _ := url.Parse(proxyRawUrl)

    client := &http.Client{
        Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)},
        Timeout:   time.Second * 30,
    }

    req, _ := http.NewRequest("GET", targetUrl, nil)
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}