Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- from urllib2 import urlopen
- import re
- from string import digits
- import time
- from xml.dom import minidom
- csv = open('stationLongLatVind.csv','w')
- #URLs used
- Base_URL = "http://opendata-download-metobs.smhi.se/api/version/latest/parameter/4.xml"
- #Base_URL = "http://opendata-download-metobs.smhi.se/api.xml"
- url = urlopen(Base_URL).read()
- soup = BeautifulSoup(url)
- ############ Labels
- csv.write("key"+";")
- csv.write("updated"+";")
- csv.write("latitude"+";")
- csv.write("longitude")
- csv.write("\n")
- i=0
- for station in soup.find_all("station"):
- for key in station.find_all("ns2:key"):
- csv.write(''.join(key.findAll(text=True))+";") #key
- for key in station.find_all("ns2:updated"):
- csv.write(''.join(key.findAll(text=True))+";") #updated
- csv.write(''.join(station.latitude.contents)+";") #latitude
- csv.write(''.join(station.longitude.contents)) #longitude
- csv.write("\n")
- print i
- i=i+1
- csv.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement