I used the following program to create a list of cities obtained from a website. Now I want to find the name of city (argument) from the list I created. How do I do that?
In other words, how do I find an object from a list? I tried: listOfCities.find (city)
, I got an error as the attribute find was not found.
def weatherNow (city):
import urllib
connection = urllib.urlopen("http://weather.canoe.ca/Weather/World.html")
weather = connection.read()
connection.close()
cityLoc = weather.find('class="weatherred"')
cityEnd = weather.find("</a>", cityLoc)
if city != -1:
listOfCities = []
while cityLoc != -1:
cityNames = weather[cityLoc+19:cityEnd-1]
listOfCities.append(cityNames)
cityLoc = weather.find('class="weatherred"', cityLoc+1)
cityEnd = weather.find("</a>", cityLoc)
print listOfCities