Playwright와 프록시
Playwright는 Chromium, Firefox, WebKit을 제어하는 브라우저 자동화 프레임워크입니다. JavaScript 렌더링이 필요한 사이트의 스크래핑에 필수적이며 프록시와 조합하면 강력한 스크래핑 도구가 됩니다.
기본 프록시 설정
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "http://gate.proxyhat.com:8080",
"username": "your_username",
"password": "your_password",
}
)
page = browser.new_page()
page.goto("https://example.com")
content = page.content()
browser.close()
컨텍스트별 프록시
browser = p.chromium.launch()
# 각 컨텍스트에 다른 프록시 할당
context1 = browser.new_context(proxy={
"server": "http://gate.proxyhat.com:8080",
"username": "user_session1",
"password": "pass",
})
context2 = browser.new_context(proxy={
"server": "http://gate.proxyhat.com:8080",
"username": "user_session2",
"password": "pass",
})
동시 스크래핑
import asyncio
from playwright.async_api import async_playwright
async def scrape_page(browser, url, proxy_config):
context = await browser.new_context(proxy=proxy_config)
page = await context.new_page()
await page.goto(url)
content = await page.content()
await context.close()
return content
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
urls = [f"https://example.com/product/{i}" for i in range(1, 11)]
tasks = [scrape_page(browser, url, {
"server": "http://gate.proxyhat.com:8080",
"username": "user", "password": "pass"
}) for url in urls]
results = await asyncio.gather(*tasks)
await browser.close()
asyncio.run(main())
스텔스 설정
- 현실적인 viewport 크기 설정
- locale과 timezone 설정
- webdriver 속성 제거
- 실제 브라우저 User-Agent 사용
핵심 요약
- Playwright는 JS 렌더링이 필요한 사이트 스크래핑에 최적입니다.
- 컨텍스트별 프록시로 각 세션에 다른 IP를 할당할 수 있습니다.
- 비동기 API로 동시 스크래핑이 가능합니다.
- ProxyHat 게이트웨이(
gate.proxyhat.com:8080)와 Playwright를 조합하십시오.






