i have code extracted using beautifulsoup website https://api.projectnimbus.org/neaodataservice.svc/nowcastset ?
after displaying location how pretty print key pair value ? location : ang mo kio latitude : 1.3546846 longitude : 103.564132 ?
from beautifulsoup import beautifulstonesoup #using bs3 import urllib2 url="https://api.projectnimbus.org/neaodataservice.svc/nowcastset" request = urllib2.request(url) request.add_header("accept", "*/*") request.add_header('accountkey', "osjeroqjtg4v7ec3kiecjw==") request.add_header('uniqueuserid', "00000000000000000000000000000001") result = urllib2.urlopen(request) xml_str = result.read() soup = beautifulstonesoup(xml_str) prop_list = [] content in soup.findall("m:properties"): props = {} prop in content.findchildren(): props[prop.name[2:]] = prop.text prop_list.append(props) print prop_list
modified:
import urllib2 beautifulsoup import beautifulstonesoup #using bs3 url="https://api.projectnimbus.org/neaodataservice.svc/nowcastset" request = urllib2.request(url) request.add_header("accept", "*/*") request.add_header('accountkey', "osjeroqjtg4v7ec3kiecjw==") request.add_header('uniqueuserid', "00000000000000000000000000000001") result = urllib2.urlopen(request) xml_str = result.read() soup = beautifulstonesoup(xml_str) prop_list = [] content in soup.findall("m:properties"): props = {} prop in content.findchildren(): props[prop.name[2:]] = prop.text prop_list.append(props) prop in prop_list: print "area: %(area)s\nlat: %(latitude)s\nlong: %(longitude)s\n" % prop
Comments
Post a Comment