How to extract latitude and longitude in a web

I have extract some infos in under the first column

from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd

url = ''
html = urlopen(url)
soup = BeautifulSoup(html, 'html.parser')


would want to only retrieve the latitude and longitude which is 35.360638, 138.727347 from the output I get.

It is in

E<br/>35.360638, 138.727347 

And also, is there a better way to retrieve all the latitude and longitude from the links of / other than doing one by one?



As Brutus mentioned, it is very specific and if you wont to use etree this could be an alternativ.

  • find() <td> with the string Latitude/Longitude (WGS84)
  • findNext() its next <td>
  • grab its contents
  • replace the , and split it by the whitespace
  • by slicing the result to the first two elements you will get the list with lat and long.


data = soup.find('td', string='Latitude/Longitude (WGS84)')



You have a list of urls and loop over it – To be considerate of the website and not to be banned, run over the pages with some delay (time.sleep()).

import time
import requests
from bs4 import BeautifulSoup
urls = ['',

data = {}

for url in urls:
    r = requests.get(url)
    soup = BeautifulSoup(r.content, 'lxml')

    ll= soup.find('td', string='Latitude/Longitude (WGS84)')



{'Fuji-san, Japan': {'url': '',
  'lat': '35.360638',
  'long': '138.727347'},
 'Kita-dake, Japan': {'url': '',
  'lat': '35.674537',
  'long': '138.238833'},
 'Hotaka-dake, Japan': {'url': '',
  'lat': '36.289203',
  'long': '137.647986'},
 'Aino-dake, Japan': {'url': '',
  'lat': '35.646037',
  'long': '138.228292'},
 'Yariga-take, Japan': {'url': '',
  'lat': '36.34198',
  'long': '137.647625'}}