Skip to content

Instantly share code, notes, and snippets.

Last active Nov 18, 2017
What would you like to do?
from bs4 import BeautifulSoup
import urllib.request as req
import os.path
# xmlをダウンロード
url = ""
savename = "shelter.xml"
if not os.path.exists(savename):
req.urlretrieve(url, savename)
# ダウンロードしたxmlを開いてパース
xml = open(savename, "r", encoding="utf-8").read()
soup = BeautifulSoup(xml, 'html.parser')
info = {}
for obj in soup.find_all("shelter"):
name = obj.find('name').string
ward = obj.find('ward').string
address = obj.find('address').string
note = obj.find('notes').string
if not (ward in info):
info[ward] = []
# 結果出力
for ward in info.keys():
print("+", ward)
for name in info[ward]:
print("| -", name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment