Created
September 23, 2020 13:44
-
-
Save zakirangwala/361d9449a46b02c5e44992399dc8bb56 to your computer and use it in GitHub Desktop.
Tutorial Code : Get user location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get location | |
def get_location(): | |
try: | |
URL = 'https://iplocation.com/' | |
page = requests.get(URL, headers=headers) | |
soup = BeautifulSoup(page.content, 'html.parser') | |
city = soup.find(class_='city').get_text() | |
country = soup.find(class_='country_name').get_text() | |
latitude = soup.find(class_='lat').get_text() | |
longitude = soup.find(class_='lng').get_text() | |
return city, country, latitude, longitude | |
except Exception as e: | |
print('Error, location could not be retrieved') | |
speak('Error, location could not be retrieved') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment