News Feed Forums General Web Scraping What details can I scrape from EconoLodge.com hotel listings using Ruby?

  • What details can I scrape from EconoLodge.com hotel listings using Ruby?

    Posted by Todor Pavel on 12/20/2024 at 10:58 am

    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.

    Todor Pavel replied 2 days, 13 hours ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

Log in to reply.