2017-03-20 12 views
-2

作業中に問題が発生しました。 私は 今イムテストコーディングの解析PM10このXML to CSV Coop Project

import xml.etree.ElementTree as ET 
import requests 
import os 
Air4thaiURL = 'http://air4thai.pcd.go.th/services/getAQI_XML.php?region=2' 
resp = requests.get(Air4thaiURL) 
msg = resp.content 
tree = ET.fromstring(msg) 
for station in tree.findall('.//station/LastUpdate'): 
print ('{}'.format(
station.get('PM10'))) 

のようにPythonでCSV

とIM初心者にXMLと出力を解析するが、この

のようになりたいhttp://air4thai.pcd.go.th/services/getAQI_XML.php?region=2 からXMLデータを必要としますなし なし なし なし なし なし なし なしだから、なし なし なし なし なし なし なし なし なし

は、それは価値/イムで表示必須入力しようません:それは

Traceback (most recent call last): 
    File "C:\Users\Gistda59\Desktop\Coop - Python Script\pm10_XML.py", line 11, in <module> 
    station.get('PM10'))) 
TypeError: non-empty format string passed to object.__format__ 

を結果だよそれを解決する方法だと、このURLからCSVへのXMLの解析をアドバイスしてください。 私の問題を解決するために大変感謝しています。

答えて

0

は、あなたが何を望むか、このです:

import xml.etree.ElementTree as ET 
import requests 
import os 
Air4thaiURL = 'http://air4thai.pcd.go.th/services/getAQI_XML.php?region=2' 
resp = requests.get(Air4thaiURL) 
msg = resp.content 
tree = ET.fromstring(msg) 
for station in tree.findall('.//station/LastUpdate'): 
    if station.tag == 'LastUpdate': 
     for item in station: 
      if item.tag == 'PM10': 
       print(item.attrib)