【Python】分析自己的博客 https://www.cnblogs.com/xiandedanteng/p/?page=XX,看每个月发帖量是多少
要执行下面程序,需要安装Beautiful Soup和requests,具体安装方法请见:https://www.cnblogs.com/xiandedanteng/p/8668492.html
# 分析自己的博客 https://www.cnblogs.com/xiandedanteng/p/?page=XX,看每个月发帖量是多少
from bs4 import BeautifulSoup
import requests
import re
user_agent='Mozilla/4.0 (compatible;MEIE 5.5;windows NT)'
headers={'User-Agent':user_agent}
dic={}; #定义个字典对象,存月份和个数
#把2013年8月以来的每个月都放进去
for i in range(8,13):
yearMonth="2013-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,13):
yearMonth="2014-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,13):
yearMonth="2015-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,13):
yearMonth="2016-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,13):
yearMonth="2017-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,13):
yearMonth="2018-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,12):
yearMonth="2019-"+"{:0>2d}".format(i)
dic[yearMonth]=0
for i in range(1,90):
html=requests.get('http://www.cnblogs.com/xiandedanteng/p/?page='+str(i),headers=headers)
soup= BeautifulSoup(html.text,'html.parser',from_encoding='utf-8');
for descDiv in soup.find_all(class_="postDesc2"):
rawInfo=descDiv.text #得到class="postDesc2"的div的内容
yearMonth=re.search(r'\d{4}-\d{2}',rawInfo).group() #用正则表达式去匹配年月并取其值
# 将年月存入字典,如果存在就在原基础上加一
if yearMonth in dic:
dic[yearMonth]=dic[yearMonth]+1
else:
dic[yearMonth]=1
# 打印字典,需要再放开
for item in dic.items():
print(item)
得到的结果是:
('2013-08', 28)
('2013-09', 43)
('2013-10', 14)
('2013-11', 15)
('2013-12', 4)
('2014-01', 8)
('2014-02', 5)
('2014-03', 3)
('2014-04', 14)
('2014-05', 14)
('2014-06', 1)
('2014-07', 26)
('2014-08', 15)
('2014-09', 2)
('2014-10', 7)
('2014-11', 12)
('2014-12', 22)
('2015-01', 14)
('2015-02', 4)
('2015-03', 0)
('2015-04', 6)
('2015-05', 4)
('2015-06', 5)
('2015-07', 10)
('2015-08', 7)
('2015-09', 0)
('2015-10', 0)
('2015-11', 1)
('2015-12', 2)
('2016-01', 0)
('2016-02', 9)
('2016-03', 15)
('2016-04', 0)
('2016-05', 1)
('2016-06', 1)
('2016-07', 17)
('2016-08', 12)
('2016-09', 0)
('2016-10', 1)
('2016-11', 0)
('2016-12', 0)
('2017-01', 20)
('2017-02', 3)
('2017-03', 2)
('2017-04', 1)
('2017-05', 1)
('2017-06', 21)
('2017-07', 9)
('2017-08', 38)
('2017-09', 80)
('2017-10', 5)
('2017-11', 32)
('2017-12', 21)
('2018-01', 7)
('2018-02', 0)
('2018-03', 19)
('2018-04', 56)
('2018-05', 45)
('2018-06', 2)
('2018-07', 2)
('2018-08', 0)
('2018-09', 0)
('2018-10', 0)
('2018-11', 0)
('2018-12', 0)
('2019-01', 0)
('2019-02', 0)
('2019-03', 37)
('2019-04', 1)
('2019-05', 2)
('2019-06', 0)
('2019-07', 1)
('2019-08', 18)
('2019-09', 42)
('2019-10', 66)
('2019-11', 17)
把这个文本拷贝到Notepad++里面,将括号替换掉,然后另存为csv文件。再用Excel打开文件生成图表如下:

工程下载:https://files.cnblogs.com/files/xiandedanteng/6.everyMonthMyblog20191104.rar
--END-- 2019年11月4日09:06:52
【Python】分析自己的博客 https://www.cnblogs.com/xiandedanteng/p/?page=XX,看每个月发帖量是多少的更多相关文章
- python学习大纲目录(转自alex博客https://www.cnblogs.com/alex3714/)
day01: 介绍.基本语法.流程控制 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 ...
- crontab 问题分析 - CSDN博客 https://blog.csdn.net/tengdazhang770960436/article/details/50997297
cd /mnt/tools/trunk/plugins/personas; python update_keywords.py crontab 问题分析 crontab 问题分析 - CSDN博客 ...
- python实现文章或博客的自动摘要(附java版开源项目)
python实现文章或博客的自动摘要(附java版开源项目) 写博客的时候,都习惯给文章加入一个简介.现在可以自动完成了!TF-IDF与余弦相似性的应用(三):自动摘要 - 阮一峰的网络日志http: ...
- Python课程设计 搭建博客
安装包Github地址 Python综合设计 233博客 注意还有个email文件是需要填入自己信息的,比如最高权限账号和要发送邮件的账号密码 请安装Python2.7环境,本服务器所用环境为 设置环 ...
- 用python爬虫监控CSDN博客阅读量
作为一个博客新人,对自己博客的访问量也是很在意的,刚好在学python爬虫,所以正好利用一下,写一个python程序来监控博客文章访问量 效果 代码会自动爬取文章列表,并且获取标题和访问量,写入exc ...
- mongodb丢失数据的原因剖析 - 迎风飘来的专栏 - CSDN博客 https://blog.csdn.net/yibing548/article/details/50844310
mongodb丢失数据的原因剖析 - 迎风飘来的专栏 - CSDN博客 https://blog.csdn.net/yibing548/article/details/50844310
- FFMPEG推流到RTMP服务器命令 - weixin_37897683的博客 - CSDN博客 https://blog.csdn.net/weixin_37897683/article/details/81225228
FFMPEG推流到RTMP服务器命令 - weixin_37897683的博客 - CSDN博客 https://blog.csdn.net/weixin_37897683/article/detai ...
- python抓取51CTO博客的推荐博客的全部博文,对标题分词存入mongodb中
原文地址: python抓取51CTO博客的推荐博客的全部博文,对标题分词存入mongodb中
- 新博客 https://k8gege.org
新博客 https://k8gege.org 于2019/12/3启用,忘了发 由于博客园长期被Google误报屏蔽,导致Firefox/Chrome等浏览器无法访问博客 发现将被Google误报的文 ...
随机推荐
- 【ansible】密钥免密登陆使用重点
Ansible 密钥免密登陆使用重点 1.配置/etc/ansible/hosts 2.配置公钥以及秘钥 authorized_keys 放置公钥文件 .ssh 放置密钥文件 密钥文件名称必须为 id ...
- 在Linux中安装适用于arm64位的nodejs
# 安装适用于arm64位的nodejs runtime v10.16.3 mkdir /runtimes cd /runtimes wget https://nodejs.org/dist/v10. ...
- K8S 1.12大特性最快最深度解析:Kubernetes CSI Snapshot(下)
Kubernetes CSI Snapshot(下篇) 目标目前在Kuberentes中,卷插件仅支持配置空的存储卷.随着新的存储功能(包括卷快照和卷克隆)的提出,因此需要支持配置卷时数据填充以.例 ...
- GPU---NVIDIA GPU 计算能力
查询网址:https://developer.nvidia.com/cuda-gpus 使用,makefile文件实例: GPU= CUDNN= OPENCV= OPENMP= DEBUG= ARCH ...
- ubuntu18 搭建ftp服务器,以及文件目录权限问题
有时候呢我们有一台本地的台式机或者云服务器,我们想要搭个ftp服务器好让我们在内网/外网中方便的传输.保存文件,这样别的任何电脑啊,设备啊,只要访问这个ftp的地址,就可以进行文件传输啦!由于我现在台 ...
- ASP.NET MVC 入门7、Hellper与数据的提交与绑定
View视图 我们可以手写HTML代码, 也可以采用基类提供的Helper类完成HTM代码. 示例: <%=Html.ActionLink("首页","index& ...
- [bzoj 1471] 不相交路径 (容斥原理)
题目描述 给出一个N(n<=150)N(n<=150)N(n<=150)个结点的有向无环简单图.给出444个不同的点aaa,bbb,ccc,ddd,定义不相交路径为两条路径,两条路径 ...
- LightOJ-1008-Fibsieve`s Fantabulous Birthday(推公式)
链接: https://vjudge.net/problem/LightOJ-1008 题意: Fibsieve had a fantabulous (yes, it's an actual word ...
- 靠边的列表如果没有设置margin-left:20px,那么是看不到列表序号的。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- redis默认端口6379以其名命名,是我孤陋寡闻了,是名性感美女(梅尔兹)
阿莱西亚-梅尔兹Alessia Merz ,这位亚平宁半岛的性感女人,自从结婚之后就逐渐的淡出了人们的实现,曾经的尤文教母已经现在已经是两个孩子的母亲,但是最近的梅尔兹开始蠢蠢欲动,在相夫教子的同时, ...