0

このウェブサイトhttps://api.projectnimbus.org/neaodataservice.svc/NowcastSetから beautifulsoup を使用してこのコードを抽出しましたか?

すべての場所を表示した後、キーペアの値にきれいに印刷するにはどうすればよいですか? 好きな場所:Ang Mo Kio 緯度:1.3546846 経度: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 = []
for content in soup.findAll("m:properties"):
    props = {}
    for prop in content.findChildren():
        props[prop.name[2:]] = prop.text
    prop_list.append(props)

print prop_list
4

2 に答える 2

0

変更:

import urllib2
from 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 = []
for content in soup.findAll("m:properties"):
    props = {}
    for prop in content.findChildren():
        props[prop.name[2:]] = prop.text
    prop_list.append(props)

for prop in prop_list:
    print "Area: %(area)s\nLat: %(latitude)s\nLong: %(longitude)s\n" % prop
于 2013-07-15T08:38:45.150 に答える