mercredi 29 mars 2017

Web Scraping with Python (city) as parameter

def findWeather(city):
  import urllib

  connection = urllib.urlopen("http://ift.tt/2o8oqLP")
  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]

The link is provided above. The issue I have is everytime I run the program and use, say "Brussels" in Belgium, as the parameter, i.e findWeather("Brussels"), it will always print 24c as the temperature whereas (as I am writing this) it should be 19c. This is the case for many other cities provided by the site. Help on this code would be appreciated.

Thanks!




Aucun commentaire:

Enregistrer un commentaire