Utilisez Shifter avec Cheerio
Associez les proxies résidentiels et ISP de Shifter à Cheerio pour un scraping Node rapide et léger. Cheerio gère l'analyse HTML de style jQuery, Shifter gère les IP résidentielles — aucun navigateur sans interface requis.
Démarrage rapide
Installer
npm install cheerio axios https-proxy-agent Utilisation de base
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
import { load } from "cheerio";
const proxyUrl =
"customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443";
const { data: html } = await axios.get("https://example.com", {
httpsAgent: new HttpsProxyAgent(proxyUrl),
proxy: false,
});
const $ = load(html);
console.log($("h1").text());
$("article.post").each((_, el) => {
console.log($(el).find("h2").text(), "->", $(el).find("a").attr("href"));
}); Fonctionnalités
Exemples
Session persistante + exploration multi-pages
Épinglez une IP résidentielle pour toute la durée d'une exploration multi-pages. Ajoutez `country-uk` pour le ciblage géographique et `ttl-300` pour étendre la fenêtre persistante à 5 minutes.
import axios, { type AxiosInstance } from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
import { load } from "cheerio";
import { randomBytes } from "node:crypto";
function makeClient(country: string): AxiosInstance {
const sid = randomBytes(4).toString("hex");
const proxyUrl =
`customer-USERNAME-country-${country}-sid-${sid}-ttl-300:` +
`PASSWORD@p.shifter.io:443`;
return 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",
"Accept-Language": "en-US,en;q=0.9",
},
});
}
const client = makeClient("uk");
let url: string | null = "https://example.co.uk/products";
const products: { title: string; price: string }[] = [];
while (url) {
const { data: html } = await client.get(url);
const $ = load(html);
$(".product-card").each((_, el) => {
products.push({
title: $(el).find("h2").text().trim(),
price: $(el).find(".price").text().trim(),
});
});
const next = $("a.next-page").attr("href");
url = next ? new URL(next, url).toString() : null;
}
console.log(`Scraped ${products.length} products`); Scraping parallèle (rotation par requête)
Supprimez le sid pour une rotation par requête. Chaque récupération parallèle obtient une IP résidentielle différente — idéal pour accéder à une liste d'URL sans déclencher les limites de débit par IP.
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
import { load } from "cheerio";
function rotatingClient() {
// No sid -> Shifter rotates the residential IP per request.
const proxyUrl =
"customer-USERNAME-country-us:PASSWORD@p.shifter.io:443";
return axios.create({
httpsAgent: new HttpsProxyAgent(proxyUrl),
proxy: false,
timeout: 30_000,
});
}
async function scrape(url: string) {
const client = rotatingClient();
const { data: html } = await client.get(url);
const $ = load(html);
return {
url,
title: $("h1").first().text().trim(),
headings: $("h2").map((_, el) => $(el).text().trim()).get(),
};
}
const urls = [
"https://example.com/category/laptops",
"https://example.com/category/phones",
"https://example.com/category/tablets",
"https://example.com/category/wearables",
];
const results = await Promise.all(urls.map(scrape));
console.log(results); got-scraping (empreintes navigateur intégrées)
got-scraping intègre une génération d'en-têtes réaliste par-dessus got. Associez-le à Shifter pour un scraper HTTP minimaliste à l'apparence d'un navigateur, encore 100x plus rapide que Puppeteer.
// npm install got-scraping cheerio
import { gotScraping } from "got-scraping";
import { load } from "cheerio";
const proxyUrl =
"customer-USERNAME-country-de-city-berlin-sid-456DEF:PASSWORD@p.shifter.io:443";
const html = await gotScraping({
url: "https://example.de/products",
proxyUrl,
headerGeneratorOptions: {
browsers: [{ name: "chrome", minVersion: 120 }],
devices: ["desktop"],
locales: ["de-DE", "en"],
operatingSystems: ["macos", "linux"],
},
}).text();
const $ = load(html);
$(".product").each((_, el) => {
console.log({
title: $(el).find("h2").text().trim(),
price: $(el).find(".price").text().trim(),
});
}); Crawlee (crawler de production avec Shifter)
Crawlee (par Apify) gère les files d'attente, les tentatives, la persistance et la rotation des proxies nativement. Branchez Shifter comme ProxyConfiguration et laissez Crawlee orchestrer le reste.
// npm install crawlee cheerio
import { CheerioCrawler, ProxyConfiguration } from "crawlee";
const proxyConfiguration = new ProxyConfiguration({
newUrlFunction: () => {
// New residential IP per session. Crawlee rotates sessions
// automatically on bans, so stale IPs get cycled out.
const sid = Math.random().toString(36).slice(2, 10);
return `customer-USERNAME-country-fr-sid-${sid}:PASSWORD@p.shifter.io:443`;
},
});
const crawler = new CheerioCrawler({
proxyConfiguration,
maxConcurrency: 8,
async requestHandler({ request, $, enqueueLinks, log }) {
log.info(`${request.url} -> ${$("h1").text().trim()}`);
$(".article").each((_, el) => {
log.info(` ${$(el).find("h2").text().trim()}`);
});
await enqueueLinks({ selector: "a.next-page", strategy: "same-domain" });
},
});
await crawler.run([
"https://example.fr/blog",
"https://example.fr/news",
]); Questions fréquentes Questions FAQ
Questions fréquentes sur l'utilisation de Shifter avec Cheerio.
Non. Cheerio est un analyseur — il n'effectue pas de requêtes HTTP. Le proxy est configuré sur le client HTTP que vous associez à Cheerio (axios, got, undici, fetch). Une fois le HTML récupéré via Shifter, vous le transmettez à la fonction load() de Cheerio comme d'habitude.
Commencer à utiliser Shifter avec Cheerio
Associez les 205M+ proxies résidentiels et ISP de Shifter à Cheerio pour un scraping Node rapide et léger. Rotation par requête, sessions persistantes et prise en charge complète de Crawlee.