Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get coordinates from a Wikipedia page using Python?

I want to get the coordinates of a given Wikipedia page. I tried to use the Wikipedia API, however the only relevant method is the geosearch() that returns a page given a pair of coordinates and i want the exact opposite.

like image 831
JayJay Avatar asked Mar 18 '26 11:03

JayJay


1 Answers

Not sure about doing it with the Wikipedia API, but it can easily be done separately.

import requests
from bs4 import BeautifulSoup as bs
req = requests.get("https://en.wikipedia.org/wiki/Calgary").text
soup = bs(req, 'lxml')
latitude = soup.find("span", {"class": "latitude"})
longitude = soup.find("span", {"class": "longitude"})
print(latitude.text, longitude.text)
like image 63
Matthew Gaiser Avatar answered Mar 21 '26 00:03

Matthew Gaiser