Hey so I need to web scrape this website (don't use beautiful soup) to get the current temperature and I am having trouble. This is what I have so far but I keep getting either a number that isn't the temperature or -1. So any help is greatly appreciated.
def assign4(city_name):
import urllib.request
if city_name == "St. Catharines":
connection = urllib.request.urlopen("https://weather.gc.ca/city/pages/on-107_metric_e.html")
condition = str(connection.read(), "utf-8")
connection.close()
weather_condition = condition.find("Temperature:</dt>")
if weather_condition != -1:
weather_condition_end = condition.find("</dd>",weather_condition)
if weather_condition_end != -1:
weather_start = condition.find("metric-hide",0,weather_condition_end)
if weather_start != -1:
print(f"Weather Conditions in St. Catharines is {weather_start}")
else:
print("'weather_start' not working")
else:
print("'weather_condition_end' not working")
else:
print("'weather_condition' not working")
assign4("St. Catharines")
weather_startis a POSITION in the string