みずほ銀行のサイトからLoto6の最新結果をゲット。
#!/usr/bin/env python # *-# -*- coding: utf-8 -*- import urllib import re def get_result_loto_num(): url = 'http://www.takarakuji.mizuhobank.co.jp/miniloto/lt6-new.html' f = urllib.urlopen(url) html = f.read() html_uni = html.decode("sjis") result_text = re.findall(ur"回別.*?キャリーオーバー.*?円", html_uni, re.S) latest_result_text = result_text[0] count_arr = re.findall(ur"第\d+回", latest_result_text) count_num_of_latest_result = count_arr[0].encode("utf8") number_uni = re.findall(ur'<.*?>\d\d<.*?>', html_uni) number = [re.sub(ur'<.*?>(\d+)<.*?>', ur'\1', num).encode("utf8") for num in number_uni[:6]] bonus_uni_arr = re.findall(ur"ボーナス数字<.*?>.*?\d\d?<.*?>", html_uni, re.S) bonus_uni = re.findall(ur"\d\d", bonus_uni_arr[0]) bonus = bonus_uni[0].encode("utf8") result_num = number + [bonus] return [count_num_of_latest_result, result_num] if __name__ == '__main__': count_num_of_latest_result, result_num = get_result_loto_num() print count_num_of_latest_result bonus_num = result_num[6] print result_num[:6], [bonus_num]
実行結果
第468回 ['09', '17', '26', '30', '34', '40'] ['33']
もっとシンプルでスマートな方法ないかな。