Dota2基辅特锦赛正在进行,上班时候又不能看比赛,打开游戏网站吧,也不太好,写了个小脚本抓取178上的比分扳,看下比赛结果,也是极好的吧。。。

比分扳的数据是js生成的,那就直接传入参数,获取内容

clipboard.png
仔细一看这参数还挺多,Headers中参数标签
clipboard.png
再窗口中直接打开连接:

clipboard.png

使用正则查找数据吧

from bs4 import BeautifulSoup
import re
import requests

data={
    'endpoint':'three',
    'ids':'100000282,100000930,100000924,100000918,100000843',
    'callback':'jQuery112408214716044557848_1493194419017',
    '_':'1493194419018'
      }

web_data = requests.get("http://wxapi.178.com/vpgame_proxy.php",params=data)
soup = BeautifulSoup(web_data.text,'lxml')
event_list = str(soup).split('}]}}')[:-1]


def get_events(strings):
    events_name = re.findall(r'"tournamentName":"(.*?)"',strings)
    events_date = re.findall(r'(\d{4}-\d{2}-\d{2})',strings)
    events_status = re.findall(r'"status":"(\w+)"',strings)
    l_teams = re.findall(r'"leftTeam":"(.*?)"',strings)
    r_teams = re.findall(r'"rightTeam":"(.*?)"',strings)
    l_scores = re.findall(r'"leftTeamScore":"(\d+)"',strings)
    r_scores = re.findall(r'"rightTeamScore":"(\d+)"',strings)
    print('|{0!s: ^37s}|{1!s: ^20s}|'.format(events_name[0], events_date[0]))
    print('{:-^60}'.format('-'))
    
    for events_statu,l_team,l_score,r_score,r_team in zip(events_status,l_teams,l_scores,r_scores,r_teams):
        print('|{0!s: ^8s}|{1!s: ^20}| {2!s: ^1s} - {3!s: ^1s} |{4!s: ^20s}|'.format(events_statu,l_team,l_score,r_score, r_team))

for i in event_list:
    get_events(i)
    print('{:-^60}'.format('-'))

执行结果

clipboard.png

写的比较粗糙,也没有进行排序,凑合用吧


阿呆吼
257 声望10 粉丝