查看支持球队一周比赛安排的python脚本

# -*- coding: utf-8 -*-

import urllib.request
import random
import re
import datetime
from bs4 import BeautifulSoup


url = "http://www.dongqiudi.com/match/fetch_new?tab=null&date=%s&scroll_times=1&tz=-8" % (datetime.datetime.now().strftime("%Y-%m-%d"))
host = "www.dongqiudi.com"
referer = "http://www.dongqiudi.com/match"
my_team = [u'北京中赫国安', u'阿森纳', u'拜仁慕尼黑', u'中国', u'德国']



''' 
#@获取403禁止访问的网页 
'''  
my_headers=["Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",  
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36",  
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"  
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14",  
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)"]
def get_content(url, host, referer):  
    req=urllib.request.Request(url)  
    req.add_header("User-Agent",random.choice(my_headers))  
    req.add_header("Host", host)  
    req.add_header("Referer", referer)
    req.add_header("GET",url)  
    content=urllib.request.urlopen(req).read()  
    return content

 
week_day = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
match_text = get_content(url, host, referer).decode('unicode-escape')
now = datetime.datetime.now()
for i in range(1, 8):
    cur_day = now + datetime.timedelta(days = i - 1)
    next_day = now + datetime.timedelta(days = i)
    day_text = match_text[match_text.find("<th colspan=\"6\">%s" % (cur_day.strftime('%Y-%m-%d'))) : match_text.find("<th colspan=\"6\">%s" % (next_day.strftime('%Y-%m-%d')))]
    split_text = BeautifulSoup(day_text, "html.parser").get_text("", strip = True).split("<\\/tr>")
    is_print = False
    for text in split_text:
        for team in my_team:
            if text.find(team) != -1:
                if is_print == False:
                    is_print = True
                    print('**********比赛日: ' + cur_day.strftime('%Y-%m-%d') + ' ' + week_day[cur_day.weekday()] + '**********')
                match_info = re.sub(r'[\n<>\\/tda]', " ", text).split()
                print("开赛时间: %s   赛事名称: %s\n%s %s %s\n" % (match_info[0], match_info[1], match_info[2], match_info[3], match_info[4]))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值