#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import re
import datetime
import requests url_name_str='''朱子超 https://www.cnblogs.com/heroknot/
赵嘉豪 https://www.cnblogs.com/zhoajiahao/
巩景云 https://www.cnblogs.com/gongjingyun123--/
李琦 https://www.cnblogs.com/1naonao/
潘立府 https://www.cnblogs.com/plf-Jack/
胡凯琴 https://www.cnblogs.com/863652104kai/
雷俊 https://www.cnblogs.com/lucky75/
刘闯 https://www.cnblogs.com/miaowugulu/
毛毅智 https://www.cnblogs.com/acate/
葛林丽 https://www.cnblogs.com/geyatou322/
朱缘应 https://www.cnblogs.com/zhuyuanying123--/
雷鸣 https://www.cnblogs.com/leimingqq2/
赵刚 https://www.cnblogs.com/zhaogang0104/
吴锡 https://www.cnblogs.com/ZDQ1/
张岩 https://www.cnblogs.com/zuihoudebieli/
高化焱 https://www.cnblogs.com/gaohuayan/
孔凡平 https://www.cnblogs.com/WilliamKong94/
王强 https://www.cnblogs.com/bruce123/
杨文益 https://www.cnblogs.com/pythonywy/
伍开日 https://www.cnblogs.com/clarence203/
朱竹平 https://www.cnblogs.com/Hades123/
周瑞星 https://www.cnblogs.com/zrx19960128/
许长义 https://www.cnblogs.com/xcyandwxl/
储皖浏 https://www.cnblogs.com/chuwanliu/
陈石 https://www.cnblogs.com/chencharry/
徐浩 https://www.cnblogs.com/einsam/
吴奇宇 https://www.cnblogs.com/blog5434/
张天承 https://www.cnblogs.com/bladecheng/
赵志强 https://www.cnblogs.com/wsxiaoyao/
朱健 https://www.cnblogs.com/masterjian924/
魏义军 https://www.cnblogs.com/Dr-wei/
曹降祥 https://www.cnblogs.com/fengxuemuyangren/
陈跃春 https://www.cnblogs.com/chenych/
黄云 https://www.cnblogs.com/yellowcloud/
段力钢 https://www.cnblogs.com/raynduan/
刘金 https://www.cnblogs.com/itboy-newking/
''' def get_name_url_dict():
"""读取文件"""
if not os.path.exists('博客地址.txt'):
with open('博客地址.txt', 'w', encoding='utf8') as fw:
fw.write(url_name_str)
fw.flush()
print('写入文件成功...') with open('博客地址.txt', 'r', encoding='utf8') as fr:
name_urls = fr.readlines() name_url_dict = dict()
for name_url in name_urls:
name_url_split = name_url.split() name = name_url_split[0]
url = name_url_split[1] name_url_dict[name] = url print(f'同学数:{len(name_url_dict)}') return name_url_dict def request_next_url_data(next_url, url_list):
"""请求下一个网页"""
next_response = requests.get(next_url)
next_data = next_response.text
next_url_list = re.findall('href="(.*?)">(.*?)</a>', next_data) url_list.extend(next_url_list)
re_next_url = re.findall('<a href="(https://www.cnblogs.com/.{0,30}/default\.html\?page=\d+)">下一页</a>', next_data)
if re_next_url:
re_next_url = re_next_url[0]
request_next_url_data(re_next_url, url_list) return url_list def for_every_name_urls(name_url_dict):
"""循环爬取所有人的博客信息"""
s_sum = '' for name, home_url in name_url_dict.items():
# 拼接主页
s_sum = f'{s_sum}{name} {home_url}\n'
print(name, home_url) # 获取第一页的内容
response = requests.get(home_url)
data = response.text
url_list = re.findall('href="(.*?)">(.*?)</a>', data) # 判断是否存在下一页
next_url = re.findall('[^;]<a href="(https://www.*?/default\.html\?page=\d+)">下一页</a>', data)
if next_url:
next_url = next_url[0]
url_list = request_next_url_data(next_url, url_list) # 去重处理
url_set = set()
for url in url_list:
if url[0].startswith(f'{home_url}p/') and url[0].endswith('html'):
url_set.add(url)
print(url_set)
for url in url_set:
s = f'{name} {url[0]} {url[1]}'
s_sum = f'{s_sum}{s}\n' s_sum = f'{s_sum}\n' return s_sum def save_file(s_sum):
day_time = str(datetime.datetime.now()).split(' ')[0]
f = open(f'{day_time}-py9博客情况汇总.txt', 'w', encoding='utf8')
f.write(s_sum)
f.close() if __name__ == '__main__':
name_url_dict = get_name_url_dict()
s_sum = for_every_name_urls(name_url_dict)
print(s_sum)
save_file(s_sum)

Python之py9-py9博客情况获取的更多相关文章

  1. python实现文章或博客的自动摘要(附java版开源项目)

    python实现文章或博客的自动摘要(附java版开源项目) 写博客的时候,都习惯给文章加入一个简介.现在可以自动完成了!TF-IDF与余弦相似性的应用(三):自动摘要 - 阮一峰的网络日志http: ...

  2. 用python爬虫监控CSDN博客阅读量

    作为一个博客新人,对自己博客的访问量也是很在意的,刚好在学python爬虫,所以正好利用一下,写一个python程序来监控博客文章访问量 效果 代码会自动爬取文章列表,并且获取标题和访问量,写入exc ...

  3. Python课程设计 搭建博客

    安装包Github地址 Python综合设计 233博客 注意还有个email文件是需要填入自己信息的,比如最高权限账号和要发送邮件的账号密码 请安装Python2.7环境,本服务器所用环境为 设置环 ...

  4. python抓取51CTO博客的推荐博客的全部博文,对标题分词存入mongodb中

    原文地址: python抓取51CTO博客的推荐博客的全部博文,对标题分词存入mongodb中

  5. Python爬取CSDN博客文章

    0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis一点基础的东西目录 1.基础底层数据结构 2.win ...

  6. python+selenium之悠悠博客学习笔记

    1 Python之自动化测试框架selenium学习 offical website 悠悠之selenium浅谈·博客园 悠悠软件测试系列 1.1 基础环境准备 1.1.1 python包下载工具的安 ...

  7. Python 爬取CSDN博客频道

    初次接触python,写的很简单,开发工具PyCharm,python 3.4很方便 python 部分模块安装时需要其他的附属模块之类的,可以先 pip install wheel 然后可以直接下载 ...

  8. 使用原生 python 造轮子搭建博客

    这篇用来 记录一个 从零开始的 博客搭建,希望坚持下去,因为python 开发效率令人发指,所以会原生从零写 ORM ,Web 框架 前提是打好 异步 io 的基础, 使用异步,有一点要谨记,一旦开始 ...

  9. 用Python给你的博客加上水印

    之前写的博客里面用到的图片都没有加水印,今天才在别的网站上发现自己的博客居然一个字不动的出现在了别人的文章里,而且还不标注出处,简直醉了. 其实博客这种东西讲真我是很愿意让别人看得,因为自己写的也比较 ...

  10. Python 通用爬虫 和讯博客 scrapy

    目标站点需求分析 通用爬虫,获取和讯博客所有博文 涉及的库 scrapy,re,requests,mysql URL RULE 解析单页源码 保存到数据库 结果

随机推荐

  1. 【Java】 Void 类型

    void 也算一个类型,而且是基本数据类型 和其它数据类型一样提供了对应的包装类Void 每个包装类都提供一个TYPE字节实例,返回对应的原型类实例 public static void main(S ...

  2. 【Layui】03 按钮 Button

    文档位置: https://www.layui.com/doc/element/button.html 01.[按钮主题] <div> <button type="butt ...

  3. 顶级围棋AI被发现漏洞:“超人类人工智能”还有很长的路?

    原文地址: https://www.bjnews.com.cn/detail/1720537986168936.html 参考资料: (1)Can AI be superhuman? Flaws in ...

  4. gym.wrappers.Monitor报错,无法使用

    使用gym中的录制功能,报错,具体: >>> import gym >>> gym.wrappers.MonitorTraceback (most recent c ...

  5. 安装华为软件昇腾mindspore-gpu-1.9.0失败记录

    官网安装地址: https://www.mindspore.cn/install PS: 不得不说华为的软件是愈发的不好用了,这个mindspore老版本去年我是使用过的,安装也是比较方便的,搞不清这 ...

  6. Ubuntu22.04下vscode安装python代码格式化(Format Document)black模块及设置

    相关: 如何在vscode中支持python的annotation(注解,type checking)--通过设置pylance参数实现python注解的type checking ubuntu22. ...

  7. condition字符串匹配问题

    概述 freeswitch是一款简单好用的VOIP开源软交换平台. fs使用dialplan配置文件执行业务流程,condition条件变量的配置是必然会使用的,这里记录一次配置过程中的错误示范. 环 ...

  8. [rCore学习笔记 024]多道程序与协作式调度

    写在前面 本随笔是非常菜的菜鸡写的.如有问题请及时提出. 可以联系:1160712160@qq.com GitHhub:https://github.com/WindDevil (目前啥也没有 本节重 ...

  9. .NET 9 优化,抢先体验 C# 13 新特性

    前言 微软即将在 2024年11月12日发布 .NET 9 的最终版本,而08月09日发布的.NET 9 Preview 7 是最终发布前的最后一个预览版.这个版本将与.NET Conf 2024一同 ...

  10. Redis分布式锁防止缓存击穿

    一.Nuget引入 StackExchange.Redis.DistributedLock.Redis依赖 二.使用 StackExchange.Redis 对redis操作做简单封装 public ...