LoginSignup
5
5

More than 5 years have passed since last update.

札幌市消防局の災害出動一覧[Python]

Last updated at Posted at 2016-01-31

札幌市消防局がここ数日分のデータをweb上で公開しているので
Pythonで取得してみます。
今回は、その日のデータを取得するので
URLはここになります。
http://www.119.city.sapporo.jp/saigai/keihon.html

最終的にこうなります
スクリーンショット 2016-02-01 10.57.49.png

ぱっと見たところ、
スクリーンショット 2016-02-01 06.49.05.png
ここが取得する際に不要になりますね。
「トップへ戻る」
は普通に文字列削除でできるでしょう。
その下の
「昨日(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
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5