Ruby Web

Ruby open-uri über Proxy-Server mit BASIC-Authentifizierung

Hinweise zur Verwendung der open-uri-Bibliothek in der Ruby-Sprache über einen Proxy-Server mit BASIC-Authentifizierung. Beispiel für den Zugriff auf eine Website über einen Proxy und das Scraping von IP-Adressen mit nokogiri...

Shou Arisaka
1 Min. Lesezeit
13. Nov. 2025

Hinweise zur Verwendung der open-uri-Bibliothek in der Ruby-Sprache über einen Proxy-Server mit BASIC-Authentifizierung.

Beispiel für den Zugriff auf eine Website über einen Proxy und das Scraping von IP-Adressen mit 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

# => Zugriffsinformationen [IP-Adressbestätigung]
# =>
# =>
# => 111.111.142.140

Diesen Artikel teilen

Shou Arisaka 13. Nov. 2025

🔗 Links kopieren