Thanks to visit codestin.com
Credit goes to github.com

Skip to content

proxy config doesn't works. #981

@changwu

Description

@changwu

hi, everybody, I have try all the methods of proxy config but it doesn't works.

my gems is below:

selenium-webdriver (4.22.0, 4.12.0, 4.8.1)
watir (7.3.0, 7.2.2)

my code:

require 'watir'

# 设置代理服务器(这里使用示例代理,请替换为实际可用的代理)
proxy_host = 'user:[email protected]'  # 例如 '123.45.67.89'
proxy_port = '33335'  # 例如 '8080'

# 配置浏览器选项
options = {
  :args => [
    '--no-sandbox',
    '--disable-dev-shm-usage',
    '--disable-gpu',
    "--proxy-server=#{proxy_host}:#{proxy_port}"  # 设置代理
  ]
}

# 创建浏览器实例
browser = Watir::Browser.new :chrome, options: options

begin
  # 访问目标网站
  browser.goto 'https://httpbin.org/ip'
  
  # 输出页面内容(应显示代理IP而非本机IP)
  puts browser.body.text
  
rescue => e
  puts "访问出错: #{e.message}"
ensure
  # 确保浏览器关闭
  browser.close if browser.exists?
end

is there some code works for proxy??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions