Class: TripAdvisorBest::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/tripadvisor_best/scraper.rb

Instance Method Summary collapse

Instance Method Details

#get_page(url) ⇒ Object



3
4
5
# File 'lib/tripadvisor_best/scraper.rb', line 3

def get_page(url)
  Nokogiri::HTML(open(url))
end

#scrap_details_page(url) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/tripadvisor_best/scraper.rb', line 23

def scrap_details_page(url)
  page = self.get_page(url)
  highlight_details = {}
  page.css("div.main_section.listingbar").each do |e|
    if e.css(".details_wrapper div.listing_details p") != nil
      highlight_details[:description] = e.css(".details_wrapper div.listing_details p").text
    end
  end
  highlight_details
end

#scrape_listings_page(url) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tripadvisor_best/scraper.rb', line 7

def scrape_listings_page(url)
  page = self.get_page(url)
  highlights_array = []
  page.css("#WINNERVIEWER div.posRel.tcInner").each do |e|
    highlight = {
      :name => e.css(".mainName a").text,
      :location => e.css(".winnerName .smaller a").text,
      :ranking => e.css("div.posn span").text,
      :url => "https://www.tripadvisor.com/#{e.css(".mainName a").attribute("href").value}"
    }

    highlights_array << highlight
  end
  highlights_array
end