回答編集履歴
2
標準出力の追加
test
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
res = requests.get("http://www3.nhk.or.jp/sokuho/jishin/data/JishinReport.xml")
|
7
7
|
root = ET.fromstring(res.text)
|
8
8
|
|
9
|
+
# 内容の標準出力
|
10
|
+
for elem in root.iter('item'):
|
11
|
+
print(elem.attrib, elem.text)
|
12
|
+
|
9
13
|
# そのまま書き出し
|
10
14
|
from xml.dom import minidom
|
11
15
|
doc = minidom.parseString(ET.tostring(root, 'utf-8'))
|
1
書き出しの追加
test
CHANGED
@@ -5,4 +5,10 @@
|
|
5
5
|
from xml.etree import ElementTree as ET
|
6
6
|
res = requests.get("http://www3.nhk.or.jp/sokuho/jishin/data/JishinReport.xml")
|
7
7
|
root = ET.fromstring(res.text)
|
8
|
+
|
9
|
+
# そのまま書き出し
|
10
|
+
from xml.dom import minidom
|
11
|
+
doc = minidom.parseString(ET.tostring(root, 'utf-8'))
|
12
|
+
with open('test.xml','w') as f:
|
13
|
+
doc.writexml(f, encoding='utf-8', indent='', addindent=' ')
|
8
14
|
```
|