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(18100, 18120, 1):
        tikitno = str(tikitno)
        url = 'http://kaijiang.500.com/shtml/ssq/' + tikitno + '.shtml'
        gettxt = GetApiTxtByRegexp(url, regexp)
        list_content = gettxt.get_content()
        list_blue.append(list_content[-1])
        print(tikitno,'--',list_content)

    # 获取各数字篮球出现的次数
    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)

结果如下图

C:\Users\suneee\AppData\Local\Programs\Python\Python36\python.exe E:/wangjz/PyWorkSpace/LearnPython/PY1009/get_content_from_api.py
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']
['02', '09', '05', '16', '01', '01', '10', '01', '02', '15', '02', '08', '04', '09', '14', '11', '15', '05', '09', '12']
[3, 3, 0, 1, 2, 0, 0, 1, 3, 1, 1, 1, 0, 1, 2, 1]

Process finished with exit code 0

猜你喜欢

转载自www.cnblogs.com/kusy/p/9779946.html
今日推荐