【问题标题】:How to use proxy in NodeJS Selenium?如何在 NodeJS Selenium 中使用代理?
【发布时间】:2018-08-27 08:54:57
【问题描述】:

documentation 中,我读到了在构建驱动程序时使用代理集的内容:

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.chrome())
    .setProxy(proxy.manual({http: 'host:1234'}))
    .build();

当我将此代码与代理 '103.87.16.2:80' - .setProxy(proxy.manual({http: 'host:1234'})) 一起使用时,我仍然有我的家庭 IP。

有什么问题?

【问题讨论】:

标签: javascript selenium


【解决方案1】:
const { Builder } =  require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

let proxyAddress = '212.56.139.253:80'
// Setting the proxy-server option is needed to info chrome to use proxy
let option = new chrome.Options().addArguments(`--proxy-server=http://${proxyAddress}`)

const driver = new Builder()
  .forBrowser('chrome')
  .setChromeOptions(option)
  .build()

driver.get('http://whatismyip.host/')
  .then(() => console.log('DONE'))

【讨论】:

  • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
  • 感谢您的反馈,我将响应建模为尽可能接近问题的上下文。我添加了一行注释来解释我添加的唯一新内容。
  • 完美运行。我用firefox尝试了2个小时来添加代理,但根本没有用,
猜你喜欢
  • 2019-04-18
  • 2020-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-27
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
相关资源
最近更新 更多