#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://weather.yahoo.com/?p=us") print(response) html = response.read() #print(html) text = str(html) #print(text) #Use RegEx to find the data we want. fDataCrop = findall("[0-9]+°", text) print("The data cropped out of the webpage is:", fDataCrop) cDataCrop = findall("[0-9]+°", text) print("The data cropped out of the webpage is:", cDataCrop) if len(fDataCrop) != 1: print("We have a problem parsing the data! Help!") else: #Get just the digits temp = findall("[0-9]+", fDataCrop[0]) fTemp = int(temp[0]) temp = findall("[0-9]+", cDataCrop[0]) cTemp = int(temp[0]) print("The scraped F temp is:", fTemp) print("The scraped C temp is:", cTemp)