hotelSearch()

Programming Language: Python 3 (As of Jan 2022)

Description


This is a function that is called with hotelInfo(). This function uses the location from the initial Travel() call. However, hotelSearch() is using the hotel name that hotelInfo() gathered. It connects to a Google search and concatenates the hotel name string at the end of the URL = "https://www.google.com/search?q=" + hotel_name . Using Beautiful Soup, this function is able to parse the HTML code and it is coded to grab and output the price, rating, and the address.

Parameters


hotel_name

  Value of this must be a string and it is grabbed from hotelInfo() call.

  hotel_name string needs to be hotel name.

Calling Example


        
            This a hidden function that is called from hotelInfo()
        
        
    

Class Code


        
            def hotelSearch(self, hotel_name):
              URL = "https://www.google.com/search?q="+hotel_name
              headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}
              page = requests.get(URL)
              soup = BeautifulSoup(page.content,"html.parser")
              hotel_rating = soup.find('span', class_='Aq14fc')
              hotel_address = soup.find('span', class_ = 'LrzXr')
              hotel_price = soup.find('span', class_ = 'MOw9od')
              information = 'Name of Hotel: ' + hotel_name +'('+ hotel_rating.text + ')'+'\n'+'Address: ' + hotel_address.text + '\n'+ 'Price: ' + hotel_price.text + '\n'
              return infromation