getLocationDescription()

Programming Language: Python 3 (As of Jan 2022)

Description


Travel() must be initialized first before calling getLocationDescription() . This function is using the location entered in Travel() and connecting to the wikipedia website by concatenating the location string at the end of the URL = "https://en.wikipedia.org/wiki/" + self.location . Using Beatiful Soup, this function is able to parse the HTML code and it is coded to grab and output the first paragraph about the desired location that was entered as a string.

Parameters


self (None; however read description)

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

  self.location string needs to be city or country

Calling Example


        
            atlanta.getLocationDesrciption()
        
        
    

Class Code


        
            def getLocationDescription(self):
              URL = https://en.wikipedia.org/wiki/"+self.location
              page = requests.get(URL)
              soup = BeautifulSoup(page.content,"html.parser")
              results = soup.find_all("p")
              paragraphs = []
              for paragraph in results: 
                paragraphs.append(paragraph.get_text())
              print (paragraphs[2])