Ruby's web scraping libraries (Nokogiri, Mechanize) simplify HTML parsing and web interaction. Its emphasis on developer productivity allows you to quickly implement web scraping with proxies. Follow the guide below and effectively integrate Oxylabs Residential, Datacenter, Mobile, and ISP proxies with Ruby for web scraping.
Ruby is typically pre-installed on macOS, but it's often an older version. For Linux distributions like Debian/Ubuntu, use sudo apt-get update && sudo apt-get install ruby-full.
For Windows, download and install RubyInstaller from rubyinstaller.org. You can verify your installation by running ruby -v in your terminal. Now, let’s get into the Ruby proxy setup.
Ruby uses net/http or HTTParty request libraries. Based on your preference, choose HTTParty for simpler, more concise code, or net/http for greater control and flexibility.
Below are example instructions for implementing any proxy server for both libraries. If you don’t have a provider yet, feel free to take a look at our picks for top proxies in 2025.
1. Using net/http:
require 'net/http'
uri = URI('http://example.com')
http = Net::HTTP.new(uri.host, uri.port, 'your_proxy_host', 8080, 'your_user', 'your_pass')
response = http.request(Net::HTTP::Get.new(uri.request_uri))
puts response.body
2. Using HTTParty:
require 'httparty'
response = HTTParty.get('http://example.com', http_proxyaddr: 'your_proxy_host', http_proxyport: 8080, http_proxyuser: 'your_user', http_proxypass: 'your_pass')
puts response.body
Note that you should replace proxy_host, 8080, user, and pass with your specific proxy server details. Below, you’ll find the code samples for different Oxylabs proxy types: Residential, Datacenter, Mobile, and ISP Proxies.
If you’re a Residential Proxies user, modify the example code from the general setup with the following details:
1. Using net/http:
require 'net/http'
uri = URI('http://example.com')
http = Net::HTTP.new(uri.host, uri.port, 'pr.oxylabs.io', 7777, 'USERNAME', 'PASSWORD')
response = http.request(Net::HTTP::Get.new(uri.request_uri))
puts response.body
2. Using HTTParty:
require 'httparty'
response = HTTParty.get('http://example.com', http_proxyaddr: 'pr.oxylabs.io', http_proxyport: 7777, http_proxyuser: 'USERNAME', http_proxypass: 'PASSWORD')
puts response.body
The host address is now set to pr.oxylabs.io and the port number is 7777.
Also, you’ll have to replace the USERNAME and PASSWORD with your own: you can set up your proxy user's credentials in the dashboard.
To use Oxylabs Datacenter Proxies (whether that’s free proxies or premium ones), adjust the general proxy server setup with the following details:
1. Using net/http:
require 'net/http'
uri = URI('http://example.com')
http = Net::HTTP.new(uri.host, uri.port, 'dc.oxylabs.io', 8000, 'USERNAME', 'PASSWORD')
response = http.request(Net::HTTP::Get.new(uri.request_uri))
puts response.body
2. Using HTTParty:
require 'httparty'
response = HTTParty.get('http://example.com', http_proxyaddr: 'dc.oxylabs.io', http_proxyport: 8000, http_proxyuser: 'USERNAME', http_proxypass: 'PASSWORD')
puts response.body
As you can see, the port number is set as 8000 and the host is dc.oxylabs.io. Replace USERNAME and PASSWORD with your own credentials.
For Mobile Proxy server users, the host should be set as pr.oxylabs.io, the port is 7777. USERNAME and PASSWORD should be your credentials.
1. Using net/http:
require 'net/http'
uri = URI('http://example.com')
proxy_host = 'pr.oxylabs.io' #use residential proxy host.
proxy_port = 7777 # use mobile port
proxy_user = 'USERNAME'
proxy_pass = 'PASSWORD'
http = Net::HTTP.new(uri.host, uri.port, proxy_host, proxy_port, proxy_user, proxy_pass)
response = http.request(Net::HTTP::Get.new(uri.request_uri))
puts response.body
2. Using HTTParty:
require 'httparty'
response = HTTParty.get('http://example.com',
http_proxyaddr: 'pr.oxylabs.io', #use residential proxy host.
http_proxyport: 7777,
http_proxyuser: 'USERNAME',
http_proxypass: 'PASSWORD'
)
puts response.body
To use Oxylabs ISP Proxies, adjust the general proxy setup with the following details:
1. Using net/http:
require 'net/http'
uri = URI('http://example.com')
http = Net::HTTP.new(uri.host, uri.port, 'isp.oxylabs.io', 8001, 'USERNAME', 'PASSWORD')
response = http.request(Net::HTTP::Get.new(uri.request_uri))
puts response.body
2. Using HTTParty:
require 'httparty'
response = HTTParty.get('http://example.com', http_proxyaddr: 'isp.oxylabs.io', http_proxyport: 8001, http_proxyuser: 'USERNAME', http_proxypass: 'PASSWORD')
puts response.body
Port: 8001
Host: isp.oxylabs.io
Credentials: replace USERNAME and PASSWORD
Note: For additional Oxylabs’ proxy customization options, such as country-specific entry points, refer to the specific product’s documentation.
To verify that your proxy integration is working correctly, you can make a request to ip.oxylabs.io. This website returns your public IP address, allowing you to confirm that it matches the proxy's IP.
Here are code examples for testing the proxy connection:
1. Using HTTParty:
require 'httparty'
response = HTTParty.get('https://ip.oxylabs.io',
http_proxyaddr: 'pr.oxylabs.io',
http_proxyport: 7777,
http_proxyuser: 'USERNAME',
http_proxypass: 'PASSWORD'
)
puts response.body
2. Using net/http:
require 'net/http'
uri = URI('https://ip.oxylabs.io')
http = Net::HTTP.new(uri.host, uri.port, 'pr.oxylabs.io', 7777, 'USERNAME', 'PASSWORD')
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
puts response.body
Combining Ruby and premium, high-quality Oxylabs proxies can help you carry out complex web scraping tasks at no hassle. If you’re interested in learning more about how Ruby plays a role in the web scraping world, check out our “Web Scraping With Ruby” article. We also have a tool for converting cURL commands to Ruby in seconds – give it a go.
Get the latest news from data gathering world
Proxies
Advanced proxy solutions
Data Collection
Datasets
Resources
Innovation hub