Proxies
Code examples
Each example prints the exit IP. Replace USER and PASS with your proxy login.
curl
curl -x http://USER-cc-us:PASS@gw.hyperproxy.io:8888 https://api.ipify.orgPython · requests
import requests
proxy = "http://USER-cc-us:PASS@gw.hyperproxy.io:8888"
proxies = {"http": proxy, "https": proxy}
for _ in range(3):
print(requests.get("https://api.ipify.org", proxies=proxies, timeout=30).text)Python · httpx
import httpx
for _ in range(3):
with httpx.Client(proxy="http://USER-cc-us:PASS@gw.hyperproxy.io:8888", timeout=30) as client:
print(client.get("https://api.ipify.org").text)Node.js
Requires undici, or axios and https-proxy-agent.
import { fetch, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent("http://USER-cc-us:PASS@gw.hyperproxy.io:8888");
const res = await fetch("https://api.ipify.org", { dispatcher });
console.log(await res.text());Go
Keep-alive is off in the rotating example so each request opens a new connection and gets a new exit.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
proxy, _ := url.Parse("http://USER-cc-us:PASS@gw.hyperproxy.io:8888")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxy), DisableKeepAlives: true},
Timeout: 30 * time.Second,
}
for i := 0; i < 3; i++ {
res, err := client.Get("https://api.ipify.org")
if err != nil {
panic(err)
}
body, _ := io.ReadAll(res.Body)
res.Body.Close()
fmt.Println(string(body))
}
}Puppeteer & Playwright
Browsers open many connections per page, so use a session to keep one IP for the whole page.
import puppeteer from "puppeteer";
const browser = await puppeteer.launch({
args: ["--proxy-server=http://gw.hyperproxy.io:8888"],
});
const page = await browser.newPage();
await page.authenticate({ username: "USER-cc-us-session-a81f", password: "PASS" });
await page.goto("https://api.ipify.org");
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();Scrapy
Set the proxy per request in meta. Reuse the same session id to keep the IP across requests.
import scrapy
class IpSpider(scrapy.Spider):
name = "ip"
def start_requests(self):
for i in range(3):
yield scrapy.Request(
f"https://api.ipify.org/?n={i}",
meta={"proxy": "http://USER-cc-us:PASS@gw.hyperproxy.io:8888"},
)
def parse(self, response):
self.logger.info(response.text)