Bright DataとのSeleniumプロキシの統合
Seleniumプロキシ設定をセットアップし、Bright DataのプロキシIPと統合する方法を学びます
Seleniumは、最も正確なWebサイトのテストなどのために、ブラウジング環境をシミュレートするために使用される高度なブラウザー自動化ソフトウェアです。
Bright DataスーパープロキシとSeleniumの統合
- まず、
Bright Data管理画面に移動し、[Zoneの作成]をクリックします。 - [ネットワークタイプ]を選択し、[保存]をクリックします。
- Selenium内で、HTTPとHTTPSの両方のexamplezproxy.lum-superproxy.io:22225の「setProxy」関数に「ProxyIP:Port」を入力します。
- [sendKeys]の下に、Bright DataアカウントIDとプロキシZone名:
lum-customer-CUSTOMER-zone-YOURZONE
とZone設定にあるZoneパスワードを入力します。 - 例:
const {Builder, By, Key, until} = require('selenium-webdriver');
const proxy = require('selenium-webdriver/proxy');
(async function example(){
let driver = await new Builder().forBrowser('firefox').setProxy(proxy.manual({
http: 'zproxy.lum-superproxy.io:22225',
https: 'zproxy.lum-superproxy.io:22225'
})).build()
try {
await driver.get('http://lumtest.com/myip.json');
driver.switchTo().alert()
.sendKeys('lum-customer-USERNAME-zone-YOURZONE'+Key.TAB+'PASSWORD');
driver.switchTo().alert().accept();
} finally {
await driver.quit();
}
})();
プロキシマネージャーとSeleniumの統合
- 使用するネットワーク、IPタイプ、およびIPの数を使用してZoneを作成します。
- Bright Dataのプロキシマネージャーを
インストールします。 - [新しいプロキシを追加]をクリックして、必要なZoneと設定を選択し、[保存]をクリックします。
- setProxyの下のSeleniumで、ローカルIPとプロキシマネージャーポート(例:127.0.0.1:24000)を入力します
- ローカルホストIPは127.0.0.1です
- プロキシマネージャーで作成されるポートは24XXX、たとえば24000です。
- Bright Dataプロキシマネージャーはすでにスーパープロキシで認証されているため、ユーザー名とパスワードのフィールドは空のままにします。
- 例:
const {Builder, By, Key, until} = require('selenium-webdriver');
const proxy = require('selenium-webdriver/proxy');
(async function example(){
let driver = await new Builder().forBrowser('firefox').setProxy(proxy.manual({
http: '127.0.0.1:24000',
https: '127.0.0.1:24000'
})).build()
try {
await driver.get('http://lumtest.com/myip.json');
driver.switchTo().alert().accept();
} finally {
await driver.quit();
}
})();