RS_911 2020-04-28 15:58 采纳率: 0%
浏览 260
已采纳

求双色球验奖代码,求双色球验奖代码

需求:
1、爬取2020年双色球开奖结果;
2、随机生成5注自选号码;
3、统计每一期中奖情况;

要求:python实现,代码简洁(同时能很好的解决问题)

例:
开奖结果
20001期: 01,03,25,26,28,33 | 08
20002期:。。。。。。。。。。。。。。。
20003期:。。。。。。。。。。。。。。。

自选1:01,08,25,26,28,33 | 05
自选2:。。。。。。。。。。。。。。。
自选3:。。。。。。。。。。。。。。。

中奖情况展示:
20001期 自选1 ‘’三等奖“
20001期 自选2 ‘’未中奖“
。。。。。。。。。。。。

中奖展示可以用其他形式,看起来清晰就好

  • 写回答

2条回答 默认 最新

  • 吃鸡王者 2020-04-29 11:13
    关注
    from bs4 import BeautifulSoup
    import requests
    import re
    
    url='http://www.17500.cn/ssq/awardlist.php'
    res=requests.get(url)
    cont=BeautifulSoup(res.text)
    
    all={}
    for i in cont.body.tbody.find_all('tr'):
        tds=i.find_all('td')
        if '2020' not in tds[0].text:
            break
        all[tds[0].text]=re.split(r'[ +]',tds[3].text)
    #print(all)
    
    def panduan(zixuan):
        zixuan=re.split(r'[ +]',zixuan)
        for key in all:
            blue=all[key][-1]==zixuan[-1]
            red=0
            for i in zixuan[:-1]:
                if i in all[key][:-1]:
                    red+=1
            if red<=2 and blue:
                print(key,"六等奖")
    
            elif red+blue==4:
                print(key,"五等奖")
    
            elif red+blue==5:
                print(key,"四等奖")
    
            elif red==5 and blue:
                print(key,"三等奖")
    
            elif red==6 and not blue:
                print(key,"二等奖")
    
            elif red==6 and blue:
                print(key,"一等奖")
            else:
                print(key,"未中奖")       
    
    
    zixuan=['01 03 25 26 28 33+08','01 03 25 26 28 33+01','01 03 25 26 28 33+09'] 
    for i in zixuan:
        panduan(i)
    
    

    建议将爬取的结果保存到本地文件,这样之后不用每次都去网上爬取结果
    本代码只是实现了功能,代码没有做过多的优化,不过思路应该就是这样的

    一下修改后的代码,只提取当月数据,细算号码放到一个列表里,大致框架都一样,集体你可以自己调整

    from bs4 import BeautifulSoup
    import requests
    import re
    from datetime import datetime
    
    url='http://www.17500.cn/ssq/awardlist.php'
    res=requests.get(url)
    cont=BeautifulSoup(res.text)
    
    all={}
    
    
    #只提取当月数据
    date=datetime.today()
    date="{:d}-{:02d}".format(date.year,date.month)  
    #print(date)
    for i in cont.body.tbody.find_all('tr'):
        tds=i.find_all('td')
        if date not in tds[1].text:
            break
        all[tds[0].text]=re.split(r'[ +]',tds[3].text)
    print(all)
    
    
    def panduan(zixuan):
        zixuan=re.split(r'[ +]',zixuan)
        for key in all:
            blue=all[key][-1]==zixuan[-1]
            red=0
            for i in zixuan[:-1]:
                if i in all[key][:-1]:
                    red+=1
            if red<=2 and blue:
                print(key,"六等奖")
    
            elif red+blue==4:
                print(key,"五等奖")
    
            elif red+blue==5:
                print(key,"四等奖")
    
            elif red==5 and blue:
                print(key,"三等奖")
    
            elif red==6 and not blue:
                print(key,"二等奖")
    
            elif red==6 and blue:
                print(key,"一等奖")
            else:
                print(key,"未中奖")       
    
    
    #自选的号码,放到一个列表里
    zixuan=['01 03 25 26 28 33+08','01 03 25 26 28 33+01','01 03 25 26 28 33+09'] 
    for i in zixuan:
        panduan(i)
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?