-
What details can I scrape from EconoLodge.com hotel listings using Ruby?
Scraping hotel listings from EconoLodge.com using Ruby allows you to extract information such as hotel names, prices, and availability. Ruby’s open-uri library for HTTP requests and nokogiri for parsing HTML makes the scraping process straightforward. Below is a sample script for scraping hotel information from EconoLodge.
require 'open-uri' require 'nokogiri' # Target URL url = "https://www.choicehotels.com/econolodge" html = URI.open(url).read # Parse HTML doc = Nokogiri::HTML(html) # Extract hotel details doc.css('.hotel-card').each do |hotel| name = hotel.css('.hotel-name').text.strip rescue 'Name not available' price = hotel.css('.price').text.strip rescue 'Price not available' location = hotel.css('.location').text.strip rescue 'Location not available' puts "Name: #{name}, Price: #{price}, Location: #{location}" end
This script fetches the EconoLodge hotel listings page and extracts details such as hotel names, prices, and locations. Pagination can be handled by identifying the “Next” button and scraping additional pages. Adding random delays between requests prevents detection and ensures smooth operation.
Sorry, there were no replies found.
Log in to reply.