#Demonstrating reading a webpage, and then finding the information we #are interested in using regular expressions. # import urllib.request from re import findall #Read the webpage: response = urllib.request.urlopen("http://www.wsbtv.com/s/weather") html = response.read() text = html.decode() #Use regular expressions to find the data we want, which looks like: # "NN°" where the NN is replaced with digits. # Note that on extremely hot days it could be NNN and on extremely # cold days it could be just N. dataCrop = findall("[0-9]+°", text) print("The data cropped out of the webpage is:", dataCrop) if len(dataCrop) != 5: print("We have a problem parsing the data! Help!") else: #Get just the digits temp = findall("[0-9]+", dataCrop[0]) intTemp = int( temp[0] ) cTemp = 5/9 * (intTemp-32) print("F temp is:", intTemp) print("C temp is:", cTemp)