SeleniumまたはPuppeteerで無料プロキシを使用する方法

SeleniumまたはPuppeteerで無料プロキシを使用する方法

Web自動化におけるプロキシの理解

プロキシはインターネットの秘密エージェントとして機能し、IPアドレスを隠蔽することで、デジタルフロンティアを巧妙に移動することを可能にします。SeleniumとPuppeteerがブラウザの舞台で旋回するウェブ自動化の文脈では、プロキシはレート制限、地域制限、監視を回避するために不可欠です。無料のプロキシは、気まぐれで短命ではありますが、軽量でクリティカルでないスクレイピングやテストのシナリオには十分です。.

プロキシの種類とその特徴

プロキシタイプ 匿名レベル サポートされているプロトコル 典型的な使用例 信頼性
ウェブ 低~中 HTTP、HTTPS シンプルなウェブスクレイピング 低い
SOCKS4/5 高い SOCKS4、SOCKS5 複雑なプロトコル、HTTPS 中くらい
透明 なし(IPを公開) HTTP、HTTPS キャッシュ、内部使用 非常に低い
エリート/匿名 高い HTTP、HTTPS 地理ブロックの回避 中くらい

無料のプロキシリストの概要については、 https://free-proxy-list.net/ または https://www.sslproxies.org/.

Selenium で無料プロキシを使用する (Python)

1. 依存関係のインストール

pip でセレンをインストールする

最新版をダウンロード Chromeドライバー Chrome バージョンと互換性があります。.

2. Seleniumでプロキシを設定する

デジタルマリオネットであるブラウザは次のように命令できます。

from selenium import webdriver from selenium.webdriver.chrome.options import Options proxy = "186.121.235.66:8080" # 無料のプロキシに置き換えます options = Options() options.add_argument(f'--proxy-server=http://{proxy}') driver = webdriver.Chrome(options=options) driver.get('https://httpbin.org/ip') print(driver.page_source) driver.quit()

表: 一般的な Chrome プロキシスイッチ

オプション 説明
--proxy-server=http://IP:ポート HTTPプロキシを設定する
--proxy-server=https=IP:ポート HTTPSプロキシを設定する
--proxy-bypass-list=localhost;127.0.0.1 プロキシからアドレスを除外する

3. 認証付きプロキシの使用

認証付きの無料プロキシは珍しいものですが、もし見つけたら:

from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options # 認証されたプロキシにはChrome拡張機能の回避策が必要です from selenium.webdriver.common.by import By import zipfile proxy_host = 'proxy.example.com' proxy_port = 8000 proxy_user = 'user' proxy_pass = 'pass' manifest_json = """ { "version": "1.0.0", "manifest_version": 2, "name": "Chrome Proxy", "permissions": [ "proxy", "tabs", "unlimitedStorage", "storage", " ", "webRequest", "webRequestBlocking" ], "background": { "scripts": ["background.js"] } } """ background_js = f""" var config = {{ mode: "fixed_servers", rules: {{ singleProxy: {{ scheme: "http", host: "{proxy_host}", port: parseInt({proxy_port}) }}, bypassList: ["localhost"] }} }}; chrome.proxy.settings.set({{value: config, scope: "regular"}}, function() {{}}); function callbackFn(details) {{ return {{ authCredentials: {{ username: "{proxy_user}", password: "{proxy_pass}" }} }}; }} chrome.webRequest.onAuthRequired.addListener( callbackFn, {{urls: [" "]}}, ['blocking'] ); """ # プロキシ拡張機能を作成します。pluginfile = 'proxy_auth_plugin.zip' with zipfile.ZipFile(pluginfile, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) chrome_options = Options() chrome_options.add_extension(pluginfile) driver = webdriver.Chrome(options=chrome_options) driver.get('https://httpbin.org/ip')

参照: Selenium プロキシ認証 (GitHub Gist)

Puppeteer (Node.js) で無料プロキシを使用する

1. Puppeteerのインストール

npm インストール パペッティア

2. プロキシを使用してPuppeteerを起動する

ブラウザに新しいマスクを着けてみましょう:

const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ args: ['--proxy-server=http://186.121.235.66:8080'] }); const page = await browser.newPage(); await page.goto('https://httpbin.org/ip'); const body = await page.content(); console.log(body); await browser.close(); })();

3. プロキシ認証の処理

ゲートキーパーが資格情報を要求した場合:

const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ args: ['--proxy-server=http://proxy.example.com:8000'] }); const page = await browser.newPage(); await page.authenticate({ username: 'user', password: 'pass' }); await page.goto('https://httpbin.org/ip'); const body = await page.content(); console.log(body); await browser.close(); })();

4. Puppeteerでのプロキシの回転

はかないアイデンティティのバレエは、次のように編成されます。

const proxies = [ 'http://proxy1:port', 'http://proxy2:port', 'http://proxy3:port' ]; const puppeteer = require('puppeteer'); (async () => { for (const proxy of proxies) { const browser = await puppeteer.launch({ args: [`--proxy-server=${proxy}`] }); const page = await browser.newPage(); await page.goto('https://httpbin.org/ip'); const body = await page.content(); console.log(`Proxy: ${proxy}\n${body}\n`); await browser.close(); } })();

無料のプロキシソース

名前 メールアドレス 特徴
無料プロキシリスト https://free-proxy-list.net/ 大規模なHTTP/Sリストが更新されました
SSLプロキシ https://www.sslproxies.org/ HTTPSプロキシ、高速アップデート
プロキシスクレイプ https://proxyscrape.com/free-proxy-list 複数のプロトコル
スパイズワン http://spys.one/en/ 高度なフィルタリング

ベストプラクティスと制限事項

  • はかない性質: 無料プロキシは予告なく消えてしまうことが多いので、以下のようなツールを使ってプロキシの有効性を監視しましょう。 プロキシチェッカー.
  • スピードと信頼性: 遅延、タイムアウト、および時折の行き詰まりが予想されます。.
  • 安全: 機密性の高いアカウントには無料のプロキシを使用しないでください。中間者攻撃が潜んでいる可能性があります。.
  • 法的および倫理的考慮事項: 常に robots.txt と利用規約を尊重してください。.

プロキシ検証の例 (Python)

ブラウザを起動する前に、プロキシのパルスをテストします。

インポート リクエスト proxy = "186.121.235.66:8080" proxies = {"http": f"http://{proxy}", "https": f"http://{proxy}"} try: response = requests.get('https://httpbin.org/ip', proxies=proxies, timeout=5) print(response.json()) except Exception as e: print(f"Proxy failed: {e}")

リソースリンク

テオフィル・ボーヴェ

テオフィル・ボーヴェ

プロキシアナリスト

テオフィル・ボーヴェは、ProxyMist の 21 歳のプロキシ アナリストで、世界中のプロキシ サーバーの包括的なリストのキュレーションと更新を専門としています。テクノロジーとサイバー セキュリティに対する生来の適性を持つテオフィルは、信頼性の高い SOCKS、HTTP、エリート、匿名プロキシ サーバーを世界中のユーザーに無料で提供することで、チームの中核メンバーになりました。絵のように美しいリヨンの街で生まれ育ったテオフィルは、幼い頃からデジタル プライバシーとイノベーションに情熱を注いでいました。

コメント (0)

まだコメントはありません。あなたが最初のコメントを投稿できます!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です