Scrapyのプロキシ設定
Python crawling framework with its own downloader middleware stack. 下の設定で Eveses の住宅用プールに向けてください。地域指定はユーザー名の中にあるので、国を変えるのに他の設定を触る必要はありません。
proxy.eveses.com:12321 · SOCKS5 は 32325 · 199か国 · $7.35/GB から
Scrapy will not pick the proxy up from `http_proxy` for HTTPS targets. It has to go through `HttpProxyMiddleware`, and the credentials must be set on the request rather than in the URL — a proxy URL with a password in it is silently stripped from `meta["proxy"]`.
設定
# settings.py
DOWNLOADER_MIDDLEWARES = {
"scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware": 110,
"myproject.middlewares.EvesesProxyMiddleware": 100, # must run BEFORE 110
}
# middlewares.py
import base64
class EvesesProxyMiddleware:
USER = "eveses_user_country-us" # add geo tokens to the username
PASS = "YOUR_PROXY_PASSWORD"
def process_request(self, request, spider):
request.meta["proxy"] = "http://proxy.eveses.com:12321"
creds = base64.b64encode(f"{self.USER}:{self.PASS}".encode()).decode()
request.headers["Proxy-Authorization"] = f"Basic {creds}"Scrapyに関する注意
Give the middleware a lower number than HttpProxyMiddleware (110) so it sets `meta["proxy"]` first.
Rotate per request by appending a fresh `_session-…` token to the username inside `process_request`.
Leave `RETRY_TIMES` at its default; a blocked exit IP retries onto a different one automatically.
Scrapyを触らずに国を変える
eveses_user_country-deeveses_user_country-de_session-ab12cd34_lifetime-30m地域とセッションはユーザー名の中にあり、ホストやポートにはありません。国を変えてもこのページの設定はそのままで、書き換えるのは1つの文字列だけです。199か国を指定でき、その多くでは都市・州のトークンも使えます。