Skip to content

Instantly share code, notes, and snippets.

@zakirangwala
Created September 23, 2020 13:44
Show Gist options
  • Save zakirangwala/361d9449a46b02c5e44992399dc8bb56 to your computer and use it in GitHub Desktop.
Save zakirangwala/361d9449a46b02c5e44992399dc8bb56 to your computer and use it in GitHub Desktop.
Tutorial Code : Get user location
# 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