I have to scrape 3 elements from this website:
http://www.altitude-maps.com/city/170_562,Poznan,Wielkopolskie,Poland
I need latitude, longitude and elevation, so my code is:
import requests
from bs4 import BeautifulSoup as bs
url = 'http://www.altitude-maps.com/city/170_562,Poznan,Wielkopolskie,Poland'
r = requests.get(url)
soup = bs(r.content, features="html.parser")
latitude = soup.find('span', attrs={'id': 'curLat'}).get_text()
longitude = soup.find('span', attrs={'id': 'curLng'}).get_text()
elevation1 = soup.find('span', attrs={'id': 'altitude'}).get_text() # from the text in the center
elevation2 = soup.find('span', attrs={'id': 'curElevation'}).get_text() # from the box in the left
It finds values for the latitude and the longitude, but it doesn't for the elevation (in both cases). Instead of getting '80.33 m' and '80.33 m (263.55 ft)' I get white space and empty str.
Comparision of HTML from the BS and from the website:
BS_elevation1 = soup.find('span', attrs={'id': 'altitude'})
# BS_elevation1: <span id="altitude" style="font-size: 1.5em;"> </span>
# This part on the website: <span id="altitude" style="font-size: 1.5em;">80.33 m (263.55 ft)</span>
BS_elevation2 = soup.find('span', attrs={'id': 'curElevation'})
# BS_elevation2: <span id="curElevation" style=""></span>
# This part on the website: <span id="curElevation" style>80.33 m</span>
It seems like the text is available on the website, but it's not available in BeautifulSoup. I can't understand why it happens. How to get over it?