
万年日历
发布日期:2021-05-14 05:50:53
浏览次数:17
分类:精选文章
本文共 4113 字,大约阅读时间需要 13 分钟。
#Coding使用gbk编码import requestsfrom bs4 import BeautifulSoupimport xlwt#获取一年数据,以字典返回def getYear(): yearDic = {} week = 2 # 2019年1月1日为星期二 year = 2019 # 可改为所需年份,注意初始星期需调整 urlList = [] base_url = 'https://wannianrili.51240.com/ajax/?q=-{}-{}&v=18121803' #构造每个月的接口链接 for month in range(1,13): if month <10: url = base_url.format(str(year), '0'+str(month)) else: url = base_url.format(str(year), str(month)) urlList.append(url) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' } for i in range(len(urlList)): html = requests.get(urlList[i], headers=headers) soup = BeautifulSoup(html.content, 'lxml') riqiList = soup.find_all(class_='wnrl_riqi') for riqi in riqiList: dayList = [] g = riqi.find_all(class_='wnrl_td_gl') n = riqi.find_all(class_='wnrl_td_bzl') gStr = g[0].get_text() nStr = n[0].get_text() if riqi.find_all(class_='wnrl_riqi_xiu'): nStr += '(休)' week = int(week) if week == 7: week = 0 week +=1 dayList.append(str(week)) dayList.append(gStr) dayList.append(nStr) monthDic = {} monthDic[gStr] = dayList yearDic[i+1] = monthDic return yearDic, year#获取每个月的星期标题坐标def coordinates(): yearCoorDic = {} x = 2 # 初始横坐标 for month in range(1,13): monthList = [] num = x if month == 1 or month ==5 or month ==9: num = x if month <5: for day in range(7): tList = [] cross = x + 14 column = day + num tList.append(cross) tList.append(column) if day ==6: num = column +2 monthList.append(tList) elif 5 < month <9: for day in range(7): tList = [] cross = x +14*2 column = day + num tList.append(cross) tList.append(column) if day ==6: num = column +2 monthList.append(tList) elif month >8: for day in range(7): tList = [] cross = x +14*2 column = day + num tList.append(cross) tList.append(column) if day ==6: num = column +2 monthList.append(tList) yearCoorDic[month] = monthList return yearCoorDic#制作Excel模板def template(): book = xlwt.Workbook() sheet = book.add_sheet('年日历表') month_style = xlwt.easyxf('font: height 280;') week_style = xlwt.easyxf('font: height 340;}') content_style = xlwt.easyxf('font: height 280;') styleRed = xlwt.XFStyle() styleRed1 = xlwt.XFStyle() styleBlack = xlwt.XFStyle() styleBlack_ = xlwt.XFStyle() styleBlack1_ = xlwt.XFStyle() titleStyle = xlwt.XFStyle() styleContent = xlwt.XFStyle() alignment = xlwt.Alignment() alignment.vert = 0x01 styleRed.alignment = alignment styleRed.font = xlwt.Font(name=u'微软雅黑', color_index=2, bold=True) styleRed1.alignment = alignment styleBlack.alignment = alignment styleBlack_.alignment = alignment styleBlack1_.alignment = alignment titleStyle.alignment = alignment styleContent.alignment = alignment #添加字体样式 font = xlwt.Font(name=u'微软雅黑') fontRed = xlwt.Font(name=u'微软雅黑', color_index=2, bold=True) fontBlack = xlwt.Font(name=u'微软雅黑', color_index=0, bold=True) fontBlack_ = xlwt.Font(name=u'微软雅黑', color_index=23, bold=True) #设置单元格样式 for cell in [styleRed, styleRed1, styleBlack, styleBlack_, styleBlack1_, titleStyle, styleContent, alignment]:
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月13日 10时24分02秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
wxWidgets源码分析(5) - 窗口管理
2019-03-06
wxWidgets源码分析(7) - 窗口尺寸
2019-03-06
wxWidgets源码分析(8) - MVC架构
2019-03-06
wxWidgets源码分析(9) - wxString
2019-03-06
Mybatis Generator最完整配置详解
2019-03-06
[白话解析] 深入浅出熵的概念 & 决策树之ID3算法
2019-03-06
[梁山好汉说IT] 梁山好汉和抢劫银行
2019-03-06
[源码解析] 消息队列 Kombu 之 基本架构
2019-03-06
[源码分析] 消息队列 Kombu 之 启动过程
2019-03-06
[源码分析] 消息队列 Kombu 之 Consumer
2019-03-06
抉择之苦
2019-03-06
wx.NET CLI wrapper for wxWidgets
2019-03-06
ASP.NET MVC Action Filters
2019-03-06
Powershell中禁止执行脚本解决办法
2019-03-06
HTTP协议状态码详解(HTTP Status Code)
2019-03-06
OO_Unit2 多线程电梯总结
2019-03-06
04_Mysql配置文件(重要参数)
2019-03-06