python爬取足球比赛信息(一)

爬取可购买的比赛信息

import datetime
import json
import time
import requests
import pymysql
from datetime import date, timedelta



url="https://webapi.sporttery.cn/gateway/jc/football/getMatchCalculatorV1.qry?poolCode=hhad,had&channel=c"

headers={
"Content-Type":" application/json"
}

def getdata():

    responese=requests.get(url,headers).text
    responese=json.loads(responese)
    all=len(responese['value']['matchInfoList'])
    for j in range(0,all):
        day1 = responese['value']['matchInfoList'][j]['businessDate']
        print(day1)
        dslen = len(responese['value']['matchInfoList'][j]['subMatchList'])
        for i in range(0,dslen):
            num=responese['value']['matchInfoList'][j]['subMatchList'][i]['matchNum']
            addname=responese['value']['matchInfoList'][j]['subMatchList'][i]['leagueAbbName']
            zhuname=responese['value']['matchInfoList'][j]['subMatchList'][i]['homeTeamAllName']
            kename=responese['value']['matchInfoList'][j]['subMatchList'][i]['awayTeamAbbName']
            lens=len(responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'])
            for z in range(0,lens):
                hh=responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][z]['poolCode']
                if z==0 and hh=="HHAD":
                    rasheng =responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['a']
                    rhsheng=responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['h']
                    rd=responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['d']
                    rang1 = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['goalLine']
                elif z==1 and hh=="HAD":
                    asheng = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['a']
                    hsheng = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['h']
                    d = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['d']
                    rang = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['goalLine']
                elif z==0 and hh=="HAD":
                    asheng =responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['a']
                    hsheng=responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['h']
                    d=responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['d']
                    rang1 = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][0]['goalLine']
                elif z==1 and hh=="HHAD":
                    rasheng = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['a']
                    rhsheng = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['h']
                    rd = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['d']
                    rang = responese['value']['matchInfoList'][j]['subMatchList'][i]['oddsList'][1]['goalLine']
                else:
                    break
            print("-------------"+addname+"-------------")
            print(num)
            print(zhuname + "-" + kename + "[0]   胜 " + hsheng + "--平 " + d + "--负 " + asheng)
            print(zhuname + "-" + kename + "["+rang+rang1+"]   胜 " + rhsheng + "--平 " + rd + "--负 " + rasheng)

爬取比赛结果

def amidithion():
    starttime=date.today() + timedelta(days = -1)
    endtime=time.strftime("%Y-%m-%d",time.localtime())
    url="https://webapi.sporttery.cn/gateway/jc/football/getMatchResultV1.qry?matchPage=1&pcOrWap=0&leagueId=&matchBeginDate="+str(starttime)+"&matchEndDate="+str(endtime)
    response=requests.get(url).text
    print(url)
    response=json.loads(response)
    lenght=len(response['value']['matchResult'])
    for i in range(0,lenght):
        day=str(starttime).replace("-","")
        num=str(response['value']['matchResult'][i]['matchNum'])
        score=response['value']['matchResult'][i]['sectionsNo999']
        win=response['value']['matchResult'][i]['winFlag']
        goalLine=response['value']['matchResult'][i]['goalLine']
        if score=="取消":
            continue
        if win=="A":
            win="负"
        elif win=="H":
            win="胜"
        else:
            win="平"
        a=int(score[2])
        if goalLine[0]=="+":
            h=int(score[0])+int(goalLine[1])
        else:
            h=int(score[0]) - int(goalLine[1])
        if a>h:
            rwin="让负"
        elif a<h:
            rwin="让胜"
        else:
            rwin="让平"
        id = str(day + num)
        print(num+",比分:"+score+"比赛结果:"+win+",让球结果:"+rwin)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值