Beginner Question for Web Scraping in Python

Hello, I have this line of code where I can pull something specific from a url within the code. But, I want to be able to have the user enter the latitude and longitude of a
weather station and for it to obtain and display:

  • Station Name
  • Current Conditions eg. Sunny, Partly Cloudy etc.
  • Temperature in Fahrenheit
  • Elevation

So I tried to alter it with a couple of things such as latlong’s () coordinates. I’m not where to go from here to get specific results based on what the user inputs, and not specific info
that’s pulled from coordinates in the url that I provide myself in the code:

import bs4, requests

print('Enter the location: ')
lat = input()

try:
url = ‘https://forecast.weather.gov/MapClick.php?’
latlong = ‘lat={}&lon=-{}’.format(lat, lon)
res = requests.get(url + latlong)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, ‘html.parser’)
elems = soup.select(’#current-conditions > div.panel-heading > div > h2’)
stationName = elems[0].text
print(stationName)
except Exception as ex:
print(‘There was a problem retrieving the information’)

I don’t know why scraping is giving me so much trouble. Any know a good way this can be done?

This is probably what you want instead:

https://www.ncdc.noaa.gov/cdo-web/webservices/v2

That should give you access to all of the NOAA weather stations and you don’t need to use scrapy.