将Selenium代理与Bright Data集成

Learn how to setup your Selenium proxy settings and integrate with Bright Data's Proxy IPs

Selenium是高级的浏览器自动化软件,为进行最准确的网站测试等操作模拟浏览环境,与Puppeteer 类似。将Selenium与Bright Data的超级代理服务器集成,会进一步提升您的在线操作水平。

将Bright Data超级代理与Selenium集成

  • 首先进入亮数据Bright Data仪表板并点击“创建通道”。
  • 选择“网络类型”并点击保存。
  • 在Selenium中,针对HTTP和HTTPS ‘examplezproxy.lum-superproxy.io:22225’,在“setProxy”函数中填写“Proxy IP: Port”。
  • 在“sendKeys”下输入您的Bright Data帐户ID和代理通道名称:lum-customer-CUSTOMER-zone-YOURZONE以及在通道设置中找到的通道密码。
  • 例如:
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数量的通道。
  • 安装Bright Data代理管理器。
  • 点击“新建代理”并选择需要的通道和设置,点击“保存”。
  • 在Selenium中,在setProxy下,输入您的本地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();
    }
})();

Dataset Sample Request

电话咨询