【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误报的文 ...
随机推荐
- vue父子组件传值例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【MySql】牛客SQL刷题(上)
牛客SQL题目 题目链接:https://www.nowcoder.com/ta/sql 查找最晚入职员工的所有信息 select * from employees where hire_date = ...
- java中javamail收发邮件实现方法
概述 1.邮件相关的标准 厂商所提供的 JavaMail 服务程序可以有选择地实现某些邮件协议,常见的邮件协议包括: SMTP(Simple Mail Transfer Protocol) :即简单邮 ...
- 【DRF框架】路由组件
视图组件涉及的路由补充: from rest_framework.viewsets import ViewSetMixin 对路由进行了重新的分发,重写了as_view() 方法,重新封装了请求方法 ...
- unittest 运行slenium(五)---运行代码并生成HTMLTestRunner报告
整体代码如下: import os import sys import time import datetime import unittest import HTMLTestRunner # git ...
- java - day012 - 异常 , throws, throw , IO ,RandomAccessFile
异常 封装错误信息的对象 错误信息 类型 例如: NullPointerExce 空指针 提示消息 出错的行号 异常的继承结构 Throwable | - Error 系统级错误 | ...
- python ORM模块sqlalchemy的使用
1.安装sqlalchemy pip install sqlalchemy 2.导入必要的包及模块 import sqlalchemy from sqlalchemy.ext.declarative ...
- python2.7 安装pycrypto库报错
windows + python2.7 先安装VC包 https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59 ...
- 转载: Redis面试常问的问题
https://www.cnblogs.com/javazhiyin/p/9842571.html 近,阿音在为接下来的一场面试做准备,其中的内容包括redis,而且redis是重点内容. Redis ...
- 【FRDM-K64F学习笔记】使用ARM mbed和Keil MDK下载你的第一个程序
FRDM-K64F开发平台采用MK64FN1M0VLL12微控制器.该控制器包含一个带有浮点单元的ARM Cortex-M4内核.其最高工作频率为120MHz,具有256KB的RAM.1MB闪存以及许 ...