Class: Landmarks::Scraper

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

Instance Method Summary collapse

Instance Method Details

#get_landmark_page(url) ⇒ Object



35
36
37
# File 'lib/landmarks/scraper.rb', line 35

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

#get_pageObject



7
8
9
# File 'lib/landmarks/scraper.rb', line 7

def get_page
  Nokogiri::HTML(open("http://www.saint-petersburg.com/top-20-attractions/"))
end

def print_landmarks_index

Landmarks::Landmark.all.each.with_index do |el, index|
    puts "#{index+1}.\t#{el.name}"
end
nil

end



29
30
31
32
# File 'lib/landmarks/scraper.rb', line 29

def print_landmarks_urls
  Landmarks::Landmark.all.each.with_index { |el, index| puts "#{index+1}.\t#{el.url}" }
  nil
end


18
19
20
# File 'lib/landmarks/scraper.rb', line 18

def print_the_title
  puts self.get_page.css("h1").text
end

#scrape_landmark_description(url) ⇒ Object



43
44
45
# File 'lib/landmarks/scraper.rb', line 43

def scrape_landmark_description(url)
  self.get_landmark_page(url).css("p").text
end

#scrape_landmark_directions(url) ⇒ Object



47
48
49
# File 'lib/landmarks/scraper.rb', line 47

def scrape_landmark_directions(url)
  self.get_landmark_page(url).css(".prop-list").text
end

#scrape_landmark_name(url) ⇒ Object



39
40
41
# File 'lib/landmarks/scraper.rb', line 39

def scrape_landmark_name(url)
	self.get_landmark_page(url).css("h1").text
end

#scrape_landmarks_indexObject



11
12
13
14
15
# File 'lib/landmarks/scraper.rb', line 11

def scrape_landmarks_index
  self.get_page.css("h2").each do |el|
    Landmarks::Landmark.new(el.text, "http://www.saint-petersburg.com"+el.css("a").attr("href").text)
  end
end