Web Scraping with Ruby: A Comprehensive Guide Using ProxyTee
Web scraping is a valuable technique for extracting data from websites, and ProxyTee makes it even more efficient. Whether you’re a beginner or an...

Web scraping is a valuable technique for extracting data from websites, and ProxyTee makes it even more efficient. Whether you’re a beginner or an experienced developer, this guide will provide you with the skills and knowledge to become an effective web scraper in Ruby, leveraging the power of ProxyTee's rotating residential proxies.
Is Ruby Good for Web Scraping?
Ruby is an interpreted, open-source, dynamically-typed programming language that supports functional, object-oriented, and procedural development. It's designed to be simple, with elegant syntax that is easy to write and natural to read. Its focus on productivity has made it a popular choice for web scraping. In particular, Ruby is an excellent choice for scraping because of the wide range of third-party libraries available, known as 'gems.' There are gems for downloading pages, analyzing their HTML content, and extracting data. With ProxyTee, you can use Ruby to ensure your requests are coming from a variety of real-user IP addresses. This is crucial in avoiding blocks and CAPTCHAs from target websites.
In summary, web scraping in Ruby is not only possible but also easy, especially when paired with the reliability of ProxyTee's Residential Proxies.

Best Ruby Web Scraping Gems
Here are three of the best web scraping libraries for Ruby:
- Nokogiri (鋸): A robust and flexible HTML and XML parsing library with a complete API for traversing and manipulating HTML/XML documents, making it easy to extract relevant data from them.
- Mechanize: A library with headless browser functionality that provides a high-level API for automating interaction with websites. It can store and send cookies, deal with redirects, follow links, and submit forms. It also provides a history to keep track of the sites visited.
- Selenium: A Ruby binding of the most popular framework for running automated tests on web pages. It can instruct a browser to interact with a website as a human user would. This technology plays a key role in bypassing anti-bot solutions and scraping sites that rely on JavaScript for rendering or retrieving data.
Using ProxyTee for Enhanced Web Scraping
When performing web scraping tasks, especially at scale, it's essential to avoid detection and blocks. This is where ProxyTee comes in handy. Here’s how ProxyTee enhances the process:
- Unlimited Bandwidth: With ProxyTee, you don't need to worry about data overages during data-intensive operations. This feature is particularly valuable for extensive scraping projects.
- Global IP Coverage: Access over 20 million IP addresses from more than 100 countries. This ensures that your scraping can be geographically diverse, targeting specific regions or performing location-based tasks, a key feature of ProxyTee's Residential Proxies.
- Auto Rotation: The auto-rotation feature changes IP addresses automatically at intervals of 3 to 60 minutes, preventing detection and bans by target websites. This is crucial for maintaining consistent data collection without interruption.
- Multiple Protocol Support: ProxyTee supports both HTTP and SOCKS5 protocols, offering compatibility with a wide range of applications and tools, which ensures that you have a variety of options when you are scraping.
Prerequisites
Before writing any code, you need to install Ruby on your machine. Follow the guide below related to your operating system.
- Install Ruby on macOS: Ruby is usually pre-installed in macOS. However, avoid updating the system Ruby. If you wish to have the latest, use a tool like rbenv to keep it separate from the system files.
- Install Ruby on Windows: Download the RubyInstaller package, launch it, and follow the installation wizard to set up Ruby. A system restart may be required. As of Windows 10, you can also use the Windows Subsystem for Linux to install Ruby.
- Install Ruby on Linux: The best way to set up a Ruby environment in Linux is to install it via a package manager. In Debian and Ubuntu, launch:
sudo apt-get install ruby-full. Consult the guide on the official site to see all package management systems supported for other distributions.
Verify your Ruby installation with: ruby -v, which should print the Ruby version.
Build a Web Scraper in Ruby
Now let's create a Ruby web scraper using ProxyTee's residential proxies. This script will retrieve data from a website, specifically focusing on extracting information and saving it into both CSV and JSON formats.
Step 1: Initialize a Ruby project
Open your terminal, create a project folder, and enter it with: mkdir ruby-web-scraper and cd ruby-web-scraper.
Create a scraper.rb file inside the project folder with puts "Hello, World!". Then run the command ruby scraper.rb. It should print “Hello, World!”.
Step 2: Choose the Scraping Library
For this guide, let's use Nokogiri since it’s effective and efficient when the site does not use JavaScript for data retrieval. You can install the gem using: gem install nokogiri.
Then, add require "nokogiri" to the top of scraper.rb file.
Step 3: Use HTTParty to Get the Target Page
Instead of using Ruby's built-in HTTP client, we’ll use HTTParty which simplifies HTTP requests. Install it via gem install httparty, and then import it with require "httparty".
To connect to the target page and bypass bot detections you should configure the User-Agent. And to make it more effective and avoid being blocked, leverage the rotating residential IPs of ProxyTee:
require "nokogiri"require "httparty"proxy_url = "YOUR_MYPROXY_PROXY_URL" # Replace with your ProxyTee proxy URLresponse = HTTParty.get("https://example.com", { headers: { "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36", }, http_proxyaddr: URI.parse(proxy_url).host, http_proxyport: URI.parse(proxy_url).port, http_proxyuser: URI.parse(proxy_url).user, http_proxypass: URI.parse(proxy_url).password,})
Replace YOUR_MYPROXY_PROXY_URL with your actual proxy URL.
Step 4: Parse the HTML Document with Nokogiri
Pass the HTML content to Nokogiri for parsing using the code: doc = Nokogiri::HTML(response.body). Now you can use Nokogiri's API to navigate and select HTML elements.
Step 5: Define the CSS Selectors for the HTML Elements of Interest
Use your browser’s developer tools to inspect the elements and find the correct CSS selectors to collect data. For example, if your intention is to retrieve items from a list with CSS class named ‘item’, then you can use the selector .item
Step 6: Scrape Data from a Webpage with Nokogiri
Define a Struct class to store the extracted data and write code for data scraping. See code example below:
# Define a data structure for the scraped dataScrapedData = Struct.new(:title, :content)# Initialize the list to store all scraped datascraped_data_list = []# Select all item HTML elementsitems = doc.css(".item")# Loop through the items to collect needed informationitems.each do |item| # Extract item title title = item.at_css(".item-title").text # Extract item content content = item.at_css(".item-content").text # Create a data record using ScrapedData and push to list scraped_data = ScrapedData.new(title, content) scraped_data_list.push(scraped_data)end
Make sure to replace .item, .item-title, and .item-content with actual selectors from your webpage.
Step 7: Export the Scraped Data
Add the required gem by require "csv", then use this gem to export to the output.csv and use Ruby's built-in JSON to export to JSON format:
# populate the CSV output fileCSV.open("output.csv", "wb") do |csv| # write the CSV header csv << ["title", "content"] # transform each record scraped to CSV scraped_data_list.each do |item| csv << item endend# populate the JSON output fileFile.open("output.json", "wb") do |json| json << JSON.pretty_generate(scraped_data_list.map { |item| Hash[item.each_pair.to_a] })end
Step 8: Put It All Together
Here is the full example to put every step together, which shows how to integrate ProxyTee into the web scraping process in Ruby:
require "nokogiri"require "httparty"require "csv"require "json"# ProxyTee configuration (Replace with your actual proxy details)proxy_url = "YOUR_MYPROXY_PROXY_URL"# URL of the webpage to scrapetarget_url = "https://example.com"# get the target page with ProxyTeeresponse = HTTParty.get(target_url, { headers: { "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36", }, http_proxyaddr: URI.parse(proxy_url).host, http_proxyport: URI.parse(proxy_url).port, http_proxyuser: URI.parse(proxy_url).user, http_proxypass: URI.parse(proxy_url).password,})# parse the HTML document with Nokogiridoc = Nokogiri::HTML(response.body)# Define a class where to keep the scraped dataScrapedData = Struct.new(:title, :content)# initialize the list of objects to store retrieved datascraped_data_list = []# select all item HTML elements using proper CSS selectoritems = doc.css(".item")# iterate over the itemsitems.each do |item| # Extract each item title title = item.at_css(".item-title").text # Extract each item content content = item.at_css(".item-content").text # Create an instance using collected data scraped_data = ScrapedData.new(title, content) # Add each instance to the list of scraped objects scraped_data_list.push(scraped_data)end# export scraped data to CSV fileCSV.open("output.csv", "wb") do |csv| csv << ["title", "content"] scraped_data_list.each do |item| csv << item endend# export scraped data to JSON fileFile.open("output.json", "wb") do |json| json << JSON.pretty_generate(scraped_data_list.map { |item| Hash[item.each_pair.to_a] })end
Make sure to replace YOUR_MYPROXY_PROXY_URL, the target_url, and the selectors .item, .item-title, and .item-content, with actual details.
Conclusion
This tutorial has demonstrated how Ruby is a powerful language for web scraping, especially when combined with ProxyTee’s reliable proxy solutions. You've seen how to set up your environment, choose the best gems for the task, and use ProxyTee to bypass blocks and retrieve data efficiently, whether you're using Unlimited Residential Proxies or any other product from ProxyTee. This makes Ruby an ideal choice for data scraping.
While scraping can sometimes present challenges due to anti-bot systems, ProxyTee provides the robust features you need to avoid detection and achieve your goals effectively. The combination of Ruby's simple syntax and ProxyTee’s reliability allows developers to extract data from the web more seamlessly and securely. Try ProxyTee for your next web scraping project and see the difference!
Principal infrastructure engineer at ProxyTee specializing in rotating residential proxy networks, SOCKS5/HTTP tunneling, TLS fingerprint mitigation, and distributed data extraction pipelines.


