I am trying to write a method in my controller to get basic info about a Resturant, given the google maps link, and make a Resturant Object. And if possible I would like to grab the images too. I am using Active Storage for images. Here a list of what I want to scrape:
- Name
- Address
- Phone
- Website
- Cuisine
- Price Range (Number of $s)
- Rating (Number of stars)
- Hours
So far I have tried to just get the name and can't get it to work. Heres my method:
def scrape_google
google_link = params[:google_link]
page = Nokogiri::HTML(URI.open(google_link))
@restaurant = Restaurant.new
#Returant Name
restaurant_name_element = page.at_css('h1.DUwDvf.fontHeadlineLarge')
@restaurant.name = restaurant_name_element&.text&.strip if restaurant_name_element
# Output scraped information to the console
puts "Scraped Information:"
puts "Name: #{@restaurant&.name}"
render :scrape_google
end
What you're asking is against the google maps terms of service. The right way to do the kind of things you're talking about are easily available:
https://developers.google.com/maps/documentation/places/web-service