.07.09
python分享
●
●
●
#01#前言
最近突然想回顾下Python,所以按照网上的思路写了一个人民日报的历史文章阅读器(既可以阅读,也会自动下载),然后改进了下,写了一个窗体,方便界面化操作,具体的看下面文章
本文分成3部分:
1、视频演示
2、代码展示
3、下载地址
#OVER#
#02#视频演示
#OVER#
#03#具体代码
importrequests
importbs4
importos
importdatetime
importtime
importos.path#文件夹遍历函数
fromtkinterimport*
importtime
#importrequests
importcodecs
#coding=utf-8
importtkinter
importtkinterastk
year=""
month="05"
day="06"
destdir="data"
deffetchUrl(url):
功能:访问url的网页,获取网页内容并返回
参数:目标网页的url
返回:目标网页的html内容
headers={
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,
user-agent:Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/.36(KHTML,likeGecko)Chrome/68.0..Safari/.36,
}
r=requests.get(url,headers=headers)
r.raise_for_status()
r.encoding=r.apparent_encoding
returnr.text
defgetPageList(year,month,day):
功能:获取当天报纸的各版面的链接列表
参数:年,月,日
url=