python抓取每期双色球中奖号码,用于分析
获取每期双色球中奖号码,便于观察,话不多说,代码如下
# -*- coding:utf-8 -*- # __author__ :kusy # __content__:获取每期双色球中奖号码 # __date__:2018/10/12 17:08 import urllib.request import re class GetApiTxtByRegexp(object): def __init__(self, url, regexp): self.url = url self.regexp = regexp def get_content(self): page = urllib.request.urlopen(self.url) content = page.read() # print(content) content_reg = re.compile(self.regexp) list_content = re.findall(content_reg, content.decode('gbk')) return list_content if __name__ == '__main__': # 获取每期期号地址(暂时无法直接获取) # url = 'http://kaijiang.500.com/shtml/ssq/18119.shtml?0_ala_baidu' # regexp = r'' # url = 'http://kaijiang.500.com/shtml/ssq/18118.shtml' regexp = r'<li class="ball_.*?">(\d*)</li>' list_blue = [] for tikitno in range(18000, 18120, 1): tikitno = str(tikitno) url = 'http://kaijiang.500.com/shtml/ssq/' + tikitno + '.shtml' try: gettxt = GetApiTxtByRegexp(url, regexp) list_content = gettxt.get_content() list_blue.append(list_content[-1]) print(tikitno,'--',list_content) except urllib.error.HTTPError: pass # 获取各数字篮球出现的次数 list_cnt = [0] * 16 for blue in list_blue: for i in range(1,17,1): if int(blue) == i: list_cnt[i-1] += 1 print(list_blue) print(list_cnt) d = dict(zip(list(range(1, 17, 1)), list_cnt)) d = sorted(d.items(), key=lambda x: x[1], reverse=True) # 篮球出现次数排序 print(d)
结果如下图
E:\kusy\future\venv\Scripts\python.exe E:/kusy/future/double_color_ball.py 18001 -- ['01', '08', '11', '26', '28', '31', '04'] 18002 -- ['07', '18', '24', '29', '31', '33', '16'] 18003 -- ['01', '14', '16', '17', '20', '31', '04'] 18004 -- ['14', '18', '19', '26', '30', '31', '11'] 18005 -- ['02', '20', '21', '28', '31', '33', '06'] 18006 -- ['02', '07', '08', '09', '17', '29', '11'] 18007 -- ['13', '14', '20', '25', '27', '31', '12'] 18008 -- ['05', '09', '10', '12', '17', '19', '13'] 18009 -- ['05', '10', '17', '23', '26', '32', '07'] 18010 -- ['01', '08', '17', '20', '21', '22', '03'] 18011 -- ['03', '10', '21', '23', '27', '33', '11'] 18012 -- ['11', '12', '13', '19', '26', '28', '12'] 18013 -- ['06', '08', '13', '15', '22', '33', '06'] 18014 -- ['09', '12', '20', '24', '28', '31', '07'] 18015 -- ['11', '15', '20', '21', '26', '33', '15'] 18016 -- ['01', '11', '12', '18', '25', '27', '16'] 18017 -- ['03', '06', '11', '26', '30', '32', '12'] 18018 -- ['02', '12', '13', '18', '25', '27', '07'] 18019 -- ['03', '11', '12', '16', '21', '23', '09'] 18020 -- ['06', '09', '10', '14', '28', '30', '05'] 18021 -- ['03', '04', '06', '11', '23', '28', '14'] 18022 -- ['07', '14', '19', '21', '22', '23', '03'] 18023 -- ['12', '15', '16', '21', '26', '29', '16'] 18024 -- ['11', '19', '22', '26', '31', '32', '02'] 18025 -- ['04', '13', '16', '19', '21', '25', '14'] 18026 -- ['04', '07', '12', '14', '26', '32', '04'] 18027 -- ['02', '07', '09', '14', '18', '28', '05'] 18028 -- ['03', '08', '11', '14', '18', '23', '16'] 18029 -- ['01', '02', '09', '14', '22', '25', '05'] 18030 -- ['13', '14', '20', '21', '25', '33', '07'] 18031 -- ['02', '16', '18', '19', '27', '30', '14'] 18032 -- ['21', '22', '23', '24', '25', '32', '06'] 18033 -- ['04', '19', '20', '22', '28', '33', '06'] 18034 -- ['01', '05', '11', '22', '23', '26', '15'] 18035 -- ['07', '10', '11', '17', '23', '28', '15'] 18036 -- ['08', '17', '24', '26', '28', '33', '04'] 18037 -- ['01', '06', '07', '08', '27', '30', '10'] 18038 -- ['15', '23', '24', '25', '28', '29', '09'] 18039 -- ['08', '12', '18', '19', '23', '32', '03'] 18040 -- ['01', '03', '08', '13', '18', '23', '16'] 18041 -- ['07', '08', '20', '23', '24', '32', '13'] 18042 -- ['06', '10', '21', '28', '29', '31', '12'] 18043 -- ['01', '04', '06', '08', '21', '24', '07'] 18044 -- ['05', '09', '12', '17', '27', '30', '06'] 18045 -- ['03', '04', '06', '25', '26', '30', '01'] 18046 -- ['10', '13', '14', '18', '20', '31', '03'] 18047 -- ['06', '07', '12', '16', '22', '25', '07'] 18048 -- ['01', '12', '20', '25', '30', '31', '02'] 18049 -- ['01', '03', '04', '11', '19', '23', '02'] 18050 -- ['01', '02', '04', '10', '18', '19', '07'] 18051 -- ['05', '07', '20', '23', '27', '31', '04'] 18052 -- ['03', '05', '06', '09', '15', '32', '14'] 18053 -- ['01', '04', '10', '11', '14', '27', '06'] 18054 -- ['04', '06', '18', '22', '25', '33', '16'] 18055 -- ['07', '09', '10', '12', '22', '26', '07'] 18056 -- ['01', '03', '06', '20', '21', '26', '01'] 18057 -- ['05', '15', '17', '19', '20', '30', '13'] 18058 -- ['07', '12', '13', '16', '26', '31', '07'] 18059 -- ['04', '06', '08', '13', '22', '32', '11'] 18060 -- ['04', '08', '13', '25', '30', '31', '10'] 18061 -- ['09', '10', '11', '12', '18', '23', '07'] 18062 -- ['02', '18', '19', '24', '25', '33', '11'] 18063 -- ['05', '06', '10', '16', '20', '25', '12'] 18064 -- ['02', '05', '10', '11', '17', '21', '05'] 18065 -- ['01', '04', '06', '14', '28', '33', '01'] 18066 -- ['09', '16', '17', '19', '22', '26', '10'] 18067 -- ['01', '04', '09', '12', '15', '18', '05'] 18068 -- ['08', '10', '17', '20', '27', '30', '01'] 18069 -- ['06', '13', '17', '19', '23', '31', '12'] 18070 -- ['04', '09', '15', '16', '19', '27', '10'] 18071 -- ['02', '05', '06', '13', '16', '19', '03'] 18072 -- ['11', '16', '19', '22', '25', '30', '08'] 18073 -- ['02', '09', '14', '15', '16', '23', '10'] 18074 -- ['09', '11', '14', '20', '27', '30', '09'] 18075 -- ['07', '09', '12', '13', '22', '24', '11'] 18076 -- ['03', '07', '08', '15', '29', '30', '13'] 18077 -- ['02', '05', '09', '15', '20', '24', '10'] 18078 -- ['03', '10', '14', '17', '18', '30', '12'] 18079 -- ['14', '15', '17', '22', '24', '29', '13'] 18080 -- ['04', '07', '13', '20', '29', '33', '03'] 18081 -- ['01', '02', '12', '16', '20', '26', '03'] 18082 -- ['06', '12', '14', '20', '22', '24', '09'] 18083 -- ['04', '09', '18', '21', '32', '33', '03'] 18084 -- ['05', '06', '08', '12', '22', '24', '03'] 18085 -- ['04', '10', '25', '26', '30', '33', '06'] 18086 -- ['02', '07', '17', '21', '23', '26', '16'] 18087 -- ['01', '05', '10', '16', '18', '31', '03'] 18088 -- ['03', '05', '12', '29', '30', '32', '14'] 18089 -- ['06', '09', '12', '14', '18', '27', '14'] 18090 -- ['01', '02', '04', '10', '14', '23', '07'] 18091 -- ['06', '11', '13', '17', '25', '32', '07'] 18092 -- ['06', '10', '16', '19', '24', '33', '16'] 18093 -- ['04', '18', '20', '21', '29', '33', '07'] 18094 -- ['04', '07', '16', '20', '24', '30', '05'] 18095 -- ['10', '11', '12', '21', '26', '33', '09'] 18096 -- ['01', '05', '09', '20', '28', '32', '12'] 18097 -- ['01', '02', '17', '20', '25', '28', '13'] 18098 -- ['06', '10', '11', '20', '29', '32', '13'] 18099 -- ['03', '07', '08', '14', '25', '32', '06'] 18100 -- ['02', '11', '14', '15', '29', '33', '02'] 18101 -- ['01', '03', '14', '26', '29', '33', '09'] 18102 -- ['02', '06', '11', '19', '21', '28', '05'] 18103 -- ['02', '09', '15', '22', '23', '24', '16'] 18104 -- ['02', '03', '06', '19', '25', '29', '01'] 18105 -- ['04', '05', '13', '18', '19', '25', '01'] 18106 -- ['04', '18', '19', '24', '25', '26', '10'] 18107 -- ['01', '02', '05', '12', '20', '22', '01'] 18108 -- ['05', '13', '18', '21', '26', '30', '02'] 18109 -- ['10', '11', '18', '23', '31', '33', '15'] 18110 -- ['11', '13', '16', '21', '22', '23', '02'] 18111 -- ['01', '07', '14', '24', '25', '28', '08'] 18112 -- ['05', '08', '18', '25', '26', '31', '04'] 18113 -- ['01', '06', '09', '16', '25', '26', '09'] 18114 -- ['01', '07', '15', '16', '20', '27', '14'] 18115 -- ['01', '13', '19', '24', '26', '29', '11'] 18116 -- ['05', '14', '17', '22', '23', '28', '15'] 18117 -- ['08', '11', '15', '17', '23', '25', '05'] 18118 -- ['08', '12', '21', '22', '27', '31', '09'] 18119 -- ['03', '13', '14', '16', '25', '27', '12'] ['04', '16', '04', '11', '06', '11', '12', '13', '07', '03', '11', '12', '06', '07', '15', '16', '12', '07', '09', '05', '14', '03', '16', '02', '14', '04', '05', '16', '05', '07', '14', '06', '06', '15', '15', '04', '10', '09', '03', '16', '13', '12', '07', '06', '01', '03', '07', '02', '02', '07', '04', '14', '06', '16', '07', '01', '13', '07', '11', '10', '07', '11', '12', '05', '01', '10', '05', '01', '12', '10', '03', '08', '10', '09', '11', '13', '10', '12', '13', '03', '03', '09', '03', '03', '06', '16', '03', '14', '14', '07', '07', '16', '07', '05', '09', '12', '13', '13', '06', '02', '09', '05', '16', '01', '01', '10', '01', '02', '15', '02', '08', '04', '09', '14', '11', '15', '05', '09', '12'] [7, 6, 10, 6, 8, 8, 13, 2, 8, 7, 7, 9, 7, 7, 5, 9] [(7, 13), (3, 10), (12, 9), (16, 9), (5, 8), (6, 8), (9, 8), (1, 7), (10, 7), (11, 7), (13, 7), (14, 7), (2, 6), (4, 6), (15, 5), (8, 2)] Process finished with exit code 0
金瓦金銮殿,皇上看不见;
一朝出了午门口,一个鼻子两只手。
金瓦金銮殿,皇上不坐殿;
一朝出了京门口,百姓的事儿牵着走牵着走。