Integration

Shifter verwenden mit Node.js

Integrieren Sie Shifters Residential- und ISP-Proxys in wenigen Minuten in jedes Node.js-Projekt. Funktioniert nahtlos mit axios, dem nativen fetch (Node 18+), got, undici, Puppeteer und Playwright.

Schnellstart

Installieren

npm install axios https-proxy-agent

Grundlegende Nutzung

import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const proxyUrl =
  "customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443";
const agent = new HttpsProxyAgent(proxyUrl);

const { data } = await axios.get("https://ipinfo.io/json", {
  httpsAgent: agent,
  proxy: false,
});

console.log(data);
// { ip: "154.16.xxx.xxx", city: "New York", country: "US", ... }

Funktionen

Drop-in-Unterstützung für axios, nativen fetch, got, undici, node-fetch und jeden HTTP-Client, der eine Proxy-URL oder einen Agent akzeptiert
Standardmäßig Rotation pro Anfrage, mit `sid` für Sticky Sessions und `ttl-N` für zeitgesteuerte Pins von N Sekunden
Headless-Browser-Unterstützung über Puppeteer und Playwright mit einzeiliger Proxy-Konfiguration
HTTP, HTTPS und SOCKS5 Protokolle am selben Gateway-Endpunkt
Geo-Targeting in 195+ Ländern über Benutzernamensparameter - kein zusätzliches SDK erforderlich
Kompatibel mit TypeScript, ESM, CommonJS und jeder Node.js LTS-Version ab 14

Beispiele

axios + Geo-Targeted Sticky Session

Fixieren Sie eine Wohn-IP für eine gesamte Benutzersitzung, indem Sie dem Benutzernamen eine `sid` hinzufügen. Fügen Sie `country-uk`, `city-london` oder `asn-7922` für geografisches Targeting hinzu.

import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
import { randomBytes } from "node:crypto";

const sid = randomBytes(4).toString("hex");

const proxyUrl =
  `customer-USERNAME-country-uk-city-london-sid-${sid}-ttl-300:` +
  `PASSWORD@p.shifter.io:443`;

const client = axios.create({
  httpsAgent: new HttpsProxyAgent(proxyUrl),
  proxy: false,
  timeout: 30_000,
  headers: {
    "User-Agent":
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
  },
});

const login = await client.post("https://example.com/login", {
  email: "user@example.com",
  password: "secret",
});

const dashboard = await client.get("https://example.com/dashboard");
const orders = await client.get("https://example.com/orders");

console.log(login.status, dashboard.status, orders.status);

Nativer fetch (Node 18+) mit undici

Wenn Sie Node 18 oder neuer verwenden, benötigen Sie kein axios -- nutzen Sie den globalen fetch mit einem undici ProxyAgent. Kleinstmöglicher Ressourcenverbrauch.

import { ProxyAgent, setGlobalDispatcher } from "undici";

const proxyAgent = new ProxyAgent({
  uri: "http://p.shifter.io:443",
  token: `Basic ${Buffer.from(
    "customer-USERNAME-country-us-sid-456DEF:PASSWORD",
  ).toString("base64")}`,
});

setGlobalDispatcher(proxyAgent);

const r = await fetch("https://api.example.com/products?page=1");
const json = await r.json();

console.log(json);

Puppeteer mit authentifiziertem Proxy

Leiten Sie Chromium über Shifter und authentifizieren Sie sich über page.authenticate(). Kombinieren Sie `sid` mit Cookies auf Browser-Ebene, um eine stabile Sitzung für den gesamten Crawl-Vorgang zu gewährleisten.

import puppeteer from "puppeteer";

const PROXY_HOST = "p.shifter.io";
const PROXY_PORT = 443;
const PROXY_USER = "customer-USERNAME-country-de-sid-789GHI";
const PROXY_PASS = "PASSWORD";

const browser = await puppeteer.launch({
  args: [`--proxy-server=http://${PROXY_HOST}:${PROXY_PORT}`],
  headless: "new",
});

const page = await browser.newPage();
await page.authenticate({ username: PROXY_USER, password: PROXY_PASS });

await page.setUserAgent(
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
);

await page.goto("https://example.com", { waitUntil: "networkidle0" });

const title = await page.title();
const html = await page.content();

console.log(title, html.length, "bytes");

await browser.close();

Playwright (Multi-Browser)

Die Launch-Optionen von Playwright akzeptieren Proxys nativ, mit Anmeldedaten direkt inline. Das gleiche Setup funktioniert für Chromium, Firefox und WebKit.

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    server: "http://p.shifter.io:443",
    username: "customer-USERNAME-country-fr-city-paris-sid-ABC123",
    password: "PASSWORD",
  },
});

const context = await browser.newContext({
  userAgent:
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
});

const page = await context.newPage();
await page.goto("https://example.com");

const headlines = await page.locator(".headline").allTextContents();

console.log(headlines);

await browser.close();
FAQ

Häufig gefragt FAQ-Fragen

Häufige Fragen zur Verwendung von Shifter mit Node.js.

Übergeben Sie einen https-proxy-agent (oder http-proxy-agent für einfaches HTTP) über die Option httpsAgent und setzen Sie proxy: false, damit axios den Agent direkt verwendet. Das Format der Proxy-URL lautet `http://USER:PASS@p.shifter.io:443`. Dieselbe axios-Instanz kann dann für mehrere Anfragen wiederverwendet werden.

Jetzt starten

Shifter verwenden mit Node.js

Fügen Sie Shifters 205M+ Residential- und ISP-Proxys in weniger als 5 Minuten zu Ihrem Node.js-Stack hinzu. Rotation pro Anfrage, Sticky Sessions und vollständige Puppeteer- / Playwright-Unterstützung.

Shifter kostenlos testenIn Minuten eingerichtet. Jederzeit kuendbar.