def findWeather(city):
import urllib
connection = urllib.urlopen("http://www.canoe.ca/Weather/World.html")
rate = connection.read()
connection.close()
currentLoc = rate.find(city)
curr = rate.find("currentDegree")
temploc = rate.find("</span>", curr)
tempstart = rate.rfind(">", 0, temploc)
print "current temp:", rate[tempstart+1:temploc]
上面提供了链接。我遇到的问题是,每当我运行程序并使用比利时的“布鲁塞尔”作为参数,即findWeather(“布鲁塞尔”),它总是打印24摄氏度作为温度,而(在我写这篇文章时)它应该是19摄氏度。这是网站提供的许多其他城市的情况。在此代码上的帮助将不胜感激。你知道吗
谢谢!你知道吗
这个应该有用:
相关问题 更多 >
编程相关推荐