Ruby Web

Ruby open-uri via Proxy Server with BASIC Authentication

Notes on how to go through a proxy server with BASIC authentication using the open-uri library in the Ruby language. Example of accessing a site via proxy and scraping IP addresses using nokogiri...

Shou Arisaka
1 min read
Oct 29, 2025

Notes on how to go through a proxy server with BASIC authentication using the open-uri library in the Ruby language.

Example of accessing a site via proxy and scraping IP addresses using nokogiri


require 'nokogiri'
require 'open-uri'

Encoding.default_external = 'UTF-8'

url = "http://localhost:3000/ip/show.json"
url = "https://whatismyipaddress.com"
url = "https://www.cman.jp/network/support/go_access.cgi" #= > chnfirm IP addr

charset = nil
# html = open(url) do |f|
html = open(url, :proxy_http_basic_authentication => ['http://IP:Port', 'USER', 'PASS']) do |f|
# html = open(url, :proxy=>'http://198.27.115.42:3128') do |f|
# html = open(url, :proxy=>'http://38.29.152.9:53281') do |f| # => https://free-proxy-list.net
  charset = f.charset
  f.read
end
doc = Nokogiri::HTML.parse(html, nil, charset)

# require 'pry-byebug'
# binding.pry

puts doc.title

puts doc.xpath('//*[@id="section_left"]/div[3]/table/tbody/tr[1]/td').text
puts doc.xpath('//*[@id="tmContHeadStr"]/div/div[1]/div[3]/div[1]').text

# => Access Information [IP Address Confirmation]
# =>
# =>
# => 111.111.142.140

Share this article

Shou Arisaka Oct 29, 2025

๐Ÿ”— Copy Links