Class: RoadtripAdventures::Scraper
- Inherits:
-
Object
- Object
- RoadtripAdventures::Scraper
- Defined in:
- lib/roadtrip_adventures/scraper.rb
Class Method Summary collapse
Class Method Details
.scrape_destinations ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/roadtrip_adventures/scraper.rb', line 3 def self.scrape_destinations doc = Nokogiri::HTML(open("https://www.lonelyplanet.com/usa")) destinations = doc.css("a.tlist__secondary-link") destinations.each_with_index{ |destination, index| # Returns 10 "destination" options if index < 10 then new_destination = RoadtripAdventures::Destination.new new_destination.name = destinations[index].text new_destination.url = "https://www.lonelyplanet.com" + destinations[index].attr("href") end } end |