Integration

Shifter verwenden mit Apify

Integrieren Sie Shifters Residential- und ISP-Proxys in jeden Apify Actor -- Crawlee übernimmt die Warteschlange und Wiederholungsversuche, Shifter kümmert sich um die Residential-IPs. ProxyConfiguration akzeptiert Shifter-URLs nativ.

Schnellstart

Installieren

npm install apify crawlee

Grundlegende Nutzung

// main.js (an Apify Actor)
import { Actor } from "apify";
import { CheerioCrawler, ProxyConfiguration } from "crawlee";

await Actor.init();

const proxyConfiguration = new ProxyConfiguration({
  proxyUrls: [
    "customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443",
  ],
});

const crawler = new CheerioCrawler({
  proxyConfiguration,
  async requestHandler({ request, $, log }) {
    log.info(`${request.url} -> ${$("h1").text().trim()}`);
  },
});

await crawler.run(["https://example.com"]);
await Actor.exit();

Funktionen

Native ProxyConfiguration-Unterstützung in Crawlee – übergeben Sie eine Shifter-URL oder eine newUrlFunction
Kompatibel mit CheerioCrawler, PuppeteerCrawler, PlaywrightCrawler und BasicCrawler
Sitzungsgebundene Sticky-IPs über den Sitzungspool von Crawlee – gesperrte Sitzungen werden automatisch beendet
Geo-Targeting in 195+ Ländern -- Land über das Actor-Eingabeschema parametrisieren
Direkt einsetzbar für geplante Apify Console-Ausführungen, automatische Skalierung in der Apify Cloud und selbst gehostetes Crawlee
Kompatibel mit dem gesamten Apify SDK – pushData, Key-Value-Store, Anfrage-Warteschlange und Dataset-Persistenz

Beispiele

Crawlee + Rotation pro Sitzung

Crawlee behandelt Sperren und abgelaufene Sitzungen automatisch. Verwenden Sie newUrlFunction, um pro Sitzung eine neue Shifter-URL zu erstellen – wenn Crawlee eine Sitzung aufgrund einer Sperre beendet, erhält die nächste eine neue Residential-IP.

import { Actor } from "apify";
import { CheerioCrawler, ProxyConfiguration } from "crawlee";

await Actor.init();

const proxyConfiguration = new ProxyConfiguration({
  // Each session asks for a fresh URL — and Crawlee bumps the session
  // on bans, so stale IPs get cycled out automatically.
  newUrlFunction: () => {
    const sid = Math.random().toString(36).slice(2, 10);
    return `customer-USERNAME-country-uk-sid-${sid}-ttl-300:PASSWORD@p.shifter.io:443`;
  },
});

const crawler = new CheerioCrawler({
  proxyConfiguration,
  useSessionPool: true,
  persistCookiesPerSession: true,
  maxConcurrency: 8,

  async requestHandler({ request, $, enqueueLinks, log, session }) {
    log.info(`Session ${session.id} -> ${request.url}`);

    $(".product-card").each((_, el) => {
      // Push to dataset (auto-persisted by Apify)
      Actor.pushData({
        url:   request.url,
        title: $(el).find("h2").text().trim(),
        price: $(el).find(".price").text().trim(),
      });
    });

    await enqueueLinks({ selector: "a.next-page", strategy: "same-domain" });
  },

  failedRequestHandler({ request, log }) {
    log.error(`Failed after retries: ${request.url}`);
  },
});

await crawler.run(["https://example.co.uk/products"]);
await Actor.exit();

PuppeteerCrawler (JS-intensive Ziele)

Wenn das Ziel einen echten Browser benötigt, ersetzen Sie CheerioCrawler durch PuppeteerCrawler. Die gleiche ProxyConfiguration wird eingebunden – Crawlee übergibt die Shifter-URL an die Start-Argumente von Puppeteer.

import { Actor } from "apify";
import { PuppeteerCrawler, ProxyConfiguration } from "crawlee";

await Actor.init();

const proxyConfiguration = new ProxyConfiguration({
  newUrlFunction: () => {
    const sid = Math.random().toString(36).slice(2, 10);
    return `customer-USERNAME-country-de-city-berlin-sid-${sid}:PASSWORD@p.shifter.io:443`;
  },
});

const crawler = new PuppeteerCrawler({
  proxyConfiguration,
  useSessionPool: true,
  launchContext: {
    launchOptions: { headless: "new" },
  },
  maxConcurrency: 4,

  async requestHandler({ request, page, log }) {
    log.info(`Visiting ${request.url}`);
    await page.waitForSelector(".product");

    const products = await page.$$eval(".product", (els) =>
      els.map((el) => ({
        title: el.querySelector("h2")?.textContent?.trim(),
        price: el.querySelector(".price")?.textContent?.trim(),
      })),
    );

    await Actor.pushData(products);
  },
});

await crawler.run(["https://example.de/categories/electronics"]);
await Actor.exit();

Länder-spezifischer Actor mit Eingabeschema

Stellen Sie das Land als Apify Actor-Eingabe bereit. Der Actor liest es beim Start und konfiguriert Shifter für den passenden Residential-Pool. Derselbe Actor-Code funktioniert für jede Region.

// .actor/input_schema.json
{
  "title": "Localized Scraper Input",
  "type": "object",
  "schemaVersion": 1,
  "properties": {
    "startUrl": { "type": "string", "title": "Start URL", "default": "https://example.com" },
    "country":  { "type": "string", "title": "Country",   "enum": ["us","uk","de","jp","fr","br"], "default": "us" },
    "maxPages": { "type": "integer", "title": "Max Pages", "default": 100, "minimum": 1, "maximum": 5000 }
  },
  "required": ["startUrl", "country"]
}

// main.js
import { Actor } from "apify";
import { CheerioCrawler, ProxyConfiguration } from "crawlee";

await Actor.init();

const { startUrl, country, maxPages } = await Actor.getInput();

const proxyConfiguration = new ProxyConfiguration({
  newUrlFunction: () => {
    const sid = Math.random().toString(36).slice(2, 10);
    return `customer-USERNAME-country-${country}-sid-${sid}-ttl-300:PASSWORD@p.shifter.io:443`;
  },
});

const crawler = new CheerioCrawler({
  proxyConfiguration,
  maxRequestsPerCrawl: maxPages,
  useSessionPool: true,

  async requestHandler({ request, $, enqueueLinks }) {
    await Actor.pushData({
      country,
      url:   request.url,
      title: $("title").text().trim(),
      h1:    $("h1").first().text().trim(),
    });
    await enqueueLinks({ strategy: "same-domain" });
  },
});

await crawler.run([startUrl]);
await Actor.exit();

Apify SDK außerhalb von Crawlee (benutzerdefinierte Logik)

Wenn Crawlee nicht zu Ihrem Anwendungsfall passt, können Sie dennoch eine Shifter-Proxy-URL aus ProxyConfiguration abrufen und mit einem beliebigen HTTP-Client verwenden. Sitzungen, Wiederholungsversuche und Persistenz funktionieren weiterhin.

import { Actor } from "apify";
import { ProxyConfiguration } from "crawlee";
import { gotScraping } from "got-scraping";

await Actor.init();

const proxyConfiguration = new ProxyConfiguration({
  newUrlFunction: () => {
    const sid = Math.random().toString(36).slice(2, 10);
    return `customer-USERNAME-country-fr-sid-${sid}:PASSWORD@p.shifter.io:443`;
  },
});

// Pull a fresh proxy URL per logical task
async function fetchTarget(url) {
  const proxyUrl = await proxyConfiguration.newUrl();

  const html = await gotScraping({
    url,
    proxyUrl,
    headerGeneratorOptions: {
      browsers: [{ name: "chrome", minVersion: 120 }],
      locales:  ["en-US"],
    },
  }).text();

  return html;
}

const urls = [
  "https://example.fr/api/v1/products?page=1",
  "https://example.fr/api/v1/products?page=2",
  // ...
];

for (const url of urls) {
  try {
    const html = await fetchTarget(url);
    await Actor.pushData({ url, length: html.length });
  } catch (err) {
    console.error(`Failed ${url}: ${err.message}`);
  }
}

await Actor.exit();
FAQ

Häufig gefragt FAQ-Fragen

Häufige Fragen zur Verwendung von Shifter mit Apify.

Verwenden Sie die ProxyConfiguration-Klasse von Crawlee entweder mit einem `proxyUrls`-Array (eine oder mehrere Shifter-URLs) oder einer `newUrlFunction`, die pro Sitzung eine neue Shifter-URL zurückgibt. Übergeben Sie die Konfiguration an Ihren Crawler – jede Anfrage wird automatisch über Shifter geleitet.

Jetzt starten

Shifter verwenden mit Apify

Führen Sie Apify Actors über Shifters 205M+ Residential- und ISP-Proxys aus. Native Crawlee ProxyConfiguration, sitzungsgebundene Sticky-IPs und vollständige Unterstützung für Cheerio / Puppeteer / Playwright-Crawler.

Shifter kostenlos testenIn Minuten eingerichtet. Jederzeit kuendbar.