Scrapy · プロキシ設定

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-de
30分固定eveses_user_country-de_session-ab12cd34_lifetime-30m

地域とセッションはユーザー名の中にあり、ホストやポートにはありません。国を変えてもこのページの設定はそのままで、書き換えるのは1つの文字列だけです。199か国を指定でき、その多くでは都市・州のトークンも使えます。

よくある質問

Scrapyでプロキシを設定するには?›
proxy.eveses.com に向け、HTTP ならポート12321、SOCKS5 なら32325を使い、Eveses のプロキシ用ユーザー名とパスワードで認証します。正確な書き方は上のスニペットにあります。 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"]`.
Scrapyの出口の国を選ぶには?›
ホストを変えるのではなく、ユーザー名に地域トークンを付けます。eveses_user_country-de ならドイツ、eveses_user_country-us なら米国です。この方法で199か国を指定でき、都市や州のトークンでさらに絞れます。Scrapy側の設定はそれ以外何も変わりません。
Scrapyでリクエスト間に同じIPを保つには?›
セッショントークンを足します — eveses_user_country-us_session-ab12cd34_lifetime-30m。このユーザー名を使うリクエストは、有効期間が切れるまで同じアドレスから出ます。トークンを外せば、リクエストごとに新しいIPへローテーションします。
料金は?›
住宅用トラフィックは Eveses ウォレットからGB単位で課金されます。1 GB で$7.35/GB、大容量では$2.57/GB まで下がります。ツールごとの料金はなく、同じ認証情報がすべてのツールで同時に使えます。

ほかの連携

住宅用IPでScrapyを動かす

1 GB で$7.35/GB、大容量なら$2.57/GB — どのツールでも同じ認証情報。

プロキシを入手 →