Class: TouristGuide::Scraping

Inherits:
Object
  • Object
show all
Defined in:
lib/tourist_guide/scraping.rb

Instance Method Summary collapse

Instance Method Details

#page_scraping(direction_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tourist_guide/scraping.rb', line 3

def page_scraping(direction_name)
  scraped_directions =[]
  direction_name = direction_name.downcase
  # direction_name= ["malls", "park", "restaurants", "hotels", "coffee%20shops"]
  html = open("https://iq.brate.com/en/search?q=#{direction_name}&region=8&sort=2&page=1")

  scraped_page = Nokogiri::HTML(html)

  array = scraped_page.css("div.single-search-result")
  array.each do |category|
      place = {}
      name = category.css(".search-result-title h3").text.strip
      address = category.css(".source a.b-link").text.strip
      description = category.css(".search-result-title div.search-result-business-category").text.strip

      place[:name] = name
      place[:address] = address
      place[:description] = description

      scraped_directions << place
end
  return scraped_directions
end