Weather Scraper
Weather Scraper
def get_weather_data(city):
try:
url = f"https://www.weather.com/weather/today/l/{city}"
response = requests.get(url)
response.raise_for_status()
location = soup.find(
'h1', class_='CurrentConditions--location--1Ayv3').text
temperature = soup.find(
'span', class_='CurrentConditions--tempValue--3KcTQ').text
condition = soup.find(
'div', class_='CurrentConditions--phraseValue--2xXSr').text
if __name__ == "__main__":
city_code = "USCA0286:1:US" # Example city code for San Francisco
print(get_weather_data(city_code))