Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. from urllib2 import urlopen
  3. import re
  4. from string import digits
  5. import time
  6. from xml.dom import minidom
  7.  
  8. csv = open('stationLongLatVind.csv','w')
  9.  
  10. #URLs used
  11. Base_URL = "http://opendata-download-metobs.smhi.se/api/version/latest/parameter/4.xml"
  12. #Base_URL = "http://opendata-download-metobs.smhi.se/api.xml"
  13.  
  14. url = urlopen(Base_URL).read()
  15. soup = BeautifulSoup(url)
  16.  
  17. ############ Labels
  18.  
  19. csv.write("key"+";")
  20. csv.write("updated"+";")
  21. csv.write("latitude"+";")
  22. csv.write("longitude")
  23. csv.write("\n")
  24.  
  25. i=0
  26. for station in soup.find_all("station"):
  27.    
  28.     for key in station.find_all("ns2:key"):
  29.         csv.write(''.join(key.findAll(text=True))+";")  #key
  30.     for key in station.find_all("ns2:updated"):
  31.         csv.write(''.join(key.findAll(text=True))+";")  #updated
  32.     csv.write(''.join(station.latitude.contents)+";")   #latitude
  33.     csv.write(''.join(station.longitude.contents))  #longitude
  34.     csv.write("\n")
  35.  
  36.     print i
  37.     i=i+1
  38.  
  39. csv.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement