빠른 답변
Node.js에서 미국 도시 프록시를 어떻게 사용하나요?
USERNAME-country-us-state-fl-city-orlando와 같은 도시 사용자 이름으로 http://gw.metroproxies.com:7777에 대한 undici ProxyAgent을 생성하고 fetch의 dispatcher으로 전달하세요. Playwright는 proxy 옵션에서 동일한 값을 사용합니다. MetroProxies는 US$0.50/GB(2026년 10월)부터 모든 요금제에서 도시, ZIP 및 ASN 타겟팅을 포함합니다. KYC 없음; 암호화폐.
import { ProxyAgent, fetch } from 'undici';
const user = 'USERNAME-country-us-state-fl-city-orlando';
const agent = new ProxyAgent({
uri: 'http://gw.metroproxies.com:7777',
token: 'Basic ' + Buffer.from(`${user}:PASSWORD`).toString('base64'),
});
const res = await fetch('https://ipinfo.io/json', { dispatcher: agent, signal: AbortSignal.timeout(30000) });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
await agent.close();
import { ProxyAgent, fetch } from 'undici';
const cities = [['fl', 'orlando'], ['fl', 'tampa'], ['ga', 'atlanta']];
for (const [state, city] of cities) {
const user = `USERNAME-country-us-state-${state}-city-${city}`;
const agent = new ProxyAgent({
uri: 'http://gw.metroproxies.com:7777',
token: 'Basic ' + Buffer.from(`${user}:PASSWORD`).toString('base64'),
});
try {
const res = await fetch('https://ipinfo.io/json', { dispatcher: agent, signal: AbortSignal.timeout(30000) });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const info = await res.json();
console.log(city, '->', info.ip, info.city, info.region);
} catch (err) {
console.log(city, 'failed:', err.message);
} finally {
await agent.close();
}
}
import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'http://gw.metroproxies.com:7777',
username: 'USERNAME-country-us-state-fl-city-miami-session-mia01-ttl-15',
password: 'PASSWORD',
},
});
const context = await browser.newContext({ timezoneId: 'America/New_York', locale: 'en-US' });
const page = await context.newPage();
await page.goto('https://ipinfo.io/json', { timeout: 60000 });
console.log(await page.textContent('body'));
await browser.close();
Node.js에서 무엇을 주의해야 하나요?
- Keep-alive: 하나의
ProxyAgent이 연결을 재사용하므로 로테이션 모드에서는 연결이 열려 있는 동안 동일한 출구 IP를 유지합니다. 새 IP를 얻으려면 도시당 하나의 에이전트를 생성하거나 에이전트를 닫으세요. - 시간대 및 로케일: Playwright의
timezoneId및locale옵션으로 브라우저를 도시에 맞춥니다. 각 도시 페이지는 IANA 시간대를 제공합니다(마이애미:America/New_York). - SOCKS5: Chromium은 SOCKS5 프록시에 사용자 이름을 보내지 않습니다. 브라우저에서는 HTTP 포트를 사용하세요.
- 시간 초과: fetch의
AbortSignal.timeout(), Playwright의timeout. - 속도: 각 사이트에 대한 요청을 적당히 유지하고 robots.txt 및 이용 약관을 준수하세요.
다음으로 어디로 가야 하나요?
5분 설정으로 시작하고, Python 및 curl 예제와 비교하며, 프록시 위치 검사기로 출구를 확인하세요. 모든 문서: 문서.
Node.js에 대해 사람들이 또 무엇을 묻나요?
어떤 Node.js 버전이 필요한가요?
Node.js 18 이상이 필요합니다. AbortSignal.timeout과 .mjs 파일의 최상위 await를 위해서입니다. undici는 npm install undici로, Playwright는 npm install playwright으로 설치하세요.
Puppeteer도 작동하나요?
네: --proxy-server=http://gw.metroproxies.com:7777로 실행하고 첫 탐색 전에 page.authenticate({ username, password })을 호출하세요.
이 예제들은 게이트웨이에 대해 실행해 본 것인가요?
node --check으로 구문 검사를 했으며, USERNAME과 PASSWORD는 자리 표시자입니다. 본인의 자격 증명으로 실행하세요.