札幌市消防局がここ数日分のデータをweb上で公開しているので
Pythonで取得してみます。
今回は、その日のデータを取得するので
URLはここになります。
http://www.119.city.sapporo.jp/saigai/keihon.html
ぱっと見たところ、
ここが取得する際に不要になりますね。
「トップへ戻る」
は普通に文字列削除でできるでしょう。
その下の
「昨日(31日)分へ」
は日付を-1して文字列として削除すれば行けるでしょう。
出動状況取得.py
# coding: utf-8
import urllib2, re, datetime
def GET_status():
GET_URL = "http://www.119.city.sapporo.jp/saigai/keihon.html"
req = urllib2.Request(GET_URL)
response = urllib2.urlopen(req)
the_page = response.read().decode('shift_jis')
tabu_pY_ = re.sub("<.*?>","",the_page)
one = tabu_pY_.replace(u"トップへ戻る", "")
try:
todaydetail = datetime.date.today() -datetime.timedelta(1)
return one.replace(u"昨日(%s日)分へ" % todaydetail.strftime("%d"), "")
except Exception, e:
print e
if __name__ == "__main__":
i = GET_status()
print i