KO
시작하기

연동 · 자동화 및 스크래핑

Scrapling에서 HProxy를 쓰세요.

Scrapling의 각 fetcher, 세션, spider에 HProxy 레지덴셜 출구를 지정하세요.
시작하기전체 가이드 읽기
  • 5단계
  • 작동하는 코드
  • HTTP 및 SOCKS5
  • 프록시 URL에 로그인

프록시를 쓰는 이유

Scrapling에 프록시를 쓰는 이유

Scrapling은 한 패키지에 fetcher 두 개를 담은 Python 스크레이핑 프레임워크입니다. 브라우저의 TLS 지문을 쓰는 일반 HTTP와, Cloudflare 확인을 푸는 스텔스 브라우저입니다. 버전 0.4부터는 자체 스파이더 프레임워크도 제공합니다. 버전 0.5는 이전 Playwright fetcher인 DynamicFetcher를 없앴으므로, 이를 import하는 0.4용 코드는 StealthyFetcher로 옮겨야 합니다.

Scrapling은 요청이 어떻게 보이는지를 바꾸고, 요청이 나오는 주소는 그대로 여러분의 것입니다. 사이트는 주소별로 요청을 세므로, IP 하나로 하는 크롤링은 지문이 아무리 좋아도 수백 페이지 뒤에 멈춥니다. 로테이팅 레지덴셜 풀은 모든 요청이나 모든 세션에 자체 주소를 줍니다.

Setup

Scrapling에서 HProxy 설정하기

  1. 1

    fetcher를 설치하세요: pip install "scrapling[fetchers]", 그다음 브라우저를 위해 scrapling install을 한 번 실행하세요.

  2. 2

    HProxy 대시보드에서 프록시 호스트, 포트, 로그인을 복사하세요.

  3. 3

    Pass proxy= to a fetcher or a session. The HTTP fetcher also takes proxy_auth=(user, pass), which keeps the password out of the logs.

  4. 4

    For several lines, build a ProxyRotator from the list and pass it as proxy_rotator= to the session.

  5. 5

    실제 실행 전에 세션을 통해 IP 에코 페이지를 한 번 열어 주소를 확인하세요.

알아 둘 것

브라우저 fetcher는 http, https, socks4, socks5만 받으며, 로그인이 있는 SOCKS5는 브라우저에서 실패합니다. 거기서는 같은 프록시의 HTTP 줄을 쓰세요.

여기 보이는 호스트, 포트, 로그인은 형식입니다. 정확한 값은 대시보드에 있으며, 바로 복사할 수 있습니다.

Scrapling, HProxy와 함께

from scrapling.fetchers import Fetcher, StealthyFetcher

# HTTP fetcher: the login stays out of the proxy URL
page = Fetcher.get(
    "https://ipinfo.io/json",
    proxy="http://example.hproxy.com:8080",
    proxy_auth=("user-country-us", "pass"),
)
print(page.json())

# Stealth browser: same proxy, as a URL with the login inside
page = StealthyFetcher.fetch(
    "https://ipinfo.io/json",
    proxy="http://user-country-us:[email protected]:8080",
    block_webrtc=True,
)

Scrapling 질문

자주 묻는 질문

Scrapling에서 프록시를 어떻게 로테이션하나요?

With a rotating gateway you do not need to: one unchanged endpoint hands out a different exit per request. For a list of fixed lines, create ProxyRotator([...]) from scrapling.fetchers and pass it as proxy_rotator= to a session. It cycles in order and accepts a custom strategy function. A session takes proxy_rotator= or proxy=, never both.

Scrapling 세션이 프록시를 무시하는 이유는 무엇인가요?

From version 0.4 to 0.4.8, FetcherSession(proxy=...) was silently ignored and requests left from the real IP. The fix shipped in 0.4.9. Update Scrapling, then fetch an IP echo page through the session to confirm the address it shows.

Scrapling 브라우저 fetcher에서 프록시 비밀번호가 실패하는 이유는 무엇인가요?

버전 0.5.1 이전에는 브라우저 fetcher가 프록시 URL의 로그인을 퍼센트 인코딩된 그대로 브라우저에 넘겼습니다. p%40ss로 쓴 비밀번호가 p%40ss 그대로 프록시에 도착했고, 프록시는 407로 응답했습니다. 버전 0.5.1은 이를 디코딩합니다. 이전 버전에서는 server, username, password가 있는 딕셔너리로 프록시를 넘기면 입력한 그대로 로그인을 받습니다.

Scrapling은 SOCKS5 프록시를 지원하나요?

HTTP fetcher는 지원합니다. 브라우저 fetcher는 아래의 브라우저가 SOCKS5 인증을 거부하므로 로그인 없는 socks5:// 줄만 받고, socks5h://는 Invalid proxy string으로 거부합니다. 사용자 이름과 비밀번호가 있다면 같은 프록시의 HTTP 줄을 쓰세요.

로그인 흐름에는 어떤 fetcher가 프록시를 맡아야 하나요?

세션에는 고정 줄을 쓰세요. StealthySession은 요청 내내 브라우저 하나를 열어 두며, 로그인은 그 전체 기간 동안 주소가 같아야 유지됩니다. 로테이팅 줄은 상태가 이어지지 않는 Fetcher의 페이지별 읽기에 맞습니다.

Scrapling 브라우저 fetcher에서 레지덴셜 트래픽을 적게 유지하려면 어떻게 하나요?

Turn on disable_resources=True and block_ads=True. A browser loads images, fonts and trackers that a scraper never reads, and residential traffic is billed per gigabyte. Both options are off by default.

준비되시면 언제든지 시작하세요.

10초면 대시보드가 열립니다. 영업 전화도, 구독도, 최소 금액도 없습니다.