[玩耍]Python实现备份CSDN博客(未完成)
来源:互联网 发布:淘宝联盟qq群推广步揍 编辑:程序博客网 时间:2024/05/22 10:59
想着把我CSDN上所有博客的markdown源文件备份一遍,但其实没学过这方面的东西,就做了个半成品。。。以后完善吧(应该)
实现了提取所有文章的名字与其对应文章ID和发布时间,并找到编辑文档的网页。
上面这些信息提取很方便,网页源码里翻就找得到。
然后按照文件名与日期给每一篇文章建立每一个空文件夹。
但是最关键的一步是,我不知道怎么提取每一篇.md文件。。。
渲染好的已经发布的文本我不要,我要.md源文件。只有编辑文本的时候遇得到md文件,所以就得实现模拟浏览器登陆。。。然而并不会做。。。 http://write.blog.csdn.net/postedit/xxxxxxxx
是文章的编辑页面,(打开来可以是markdown编辑器也可以是传统的那个),传统的编辑器的源码里倒是可以看到带样式的每个字,但是md编辑器的源码里面就没有。。。
md编辑器有个功能叫导出到本地,可以直接把.md文件下载下来。但是每次下载生成的链接都是随机的,我也不知道怎么找到这个函数。
有没有大神会的求留言:P。
半成品代码:
#coding=utf-8'''Created on 2017年8月19日@author: XieNaoban@github: https://github.com/xienaoban@blog: http://blog.csdn.net/xienaoban'''import osimport urllib#########################################################################def log(str): print("log: " + str + ".")##########################################################################参数设定auth = "xienaoban"wsp = "C:\\Users\\xjf19\\Desktop\\"#########################################################################s = urllib.request.urlopen("http://blog.csdn.net/" + auth).read().decode('utf-8')pages = ord(s[s.find("尾页") - 3]) - ord('0') + 1fout = open(wsp + "articles.txt",'w', encoding='utf-8')log(str(pages) + " page(s) found")key = "<span class=\"link_title\"><a href=\"/" + auth + "/article/details/"key2 = "link_postdate"edit = "http://write.blog.csdn.net/postedit/"articles = 0for page in range(1, pages): url = "http://blog.csdn.net/" + auth + "/article/list/"+str(page) sc = urllib.request.urlopen(url).read().decode('utf-8') i = 0 while True: tmp = sc.find(key, i) if(tmp < i): break i = tmp + len(key) fout.write(edit) while sc[i]!='\"': fout.write(sc[i]) i += 1 i += 12 d = sc.find(key2, i) + len(key2) + 2 fout.write(" " + sc[d]+sc[d+1]+sc[d+2]+sc[d+3] + sc[d+5]+sc[d+6] + sc[d+8]+sc[d+9]) ed = sc.find("</a>",i) - 22 while i != ed: if sc[i] !='/' and sc[i] != '*' and sc[i] != '?': fout.write(sc[i]) i += 1 fout.write("\n") articles += 1fout.close()log(str(articles) + " article(s) found")fin = open(wsp + "articles.txt", "r", encoding='utf-8')wsp += "Blog\\"if not os.path.exists(wsp): os.mkdir(wsp)new_dir = 0for arti in range(0, articles): line = fin.readline() if not line: break line = line[len(edit) + 4 + 8:-1] if not os.path.exists(wsp + line): os.mkdir(wsp + line) new_dir += 1log(str(new_dir) + " directory(s) added")log("program finished")#########################################################################
阅读全文
0 0
- [玩耍]Python实现备份CSDN博客(未完成)
- Python实现CSDN博客的完整备份
- Python备份CSDN博客
- python版CSDN博客备份工具
- 备份CSDN的博客
- CSDN博客备份
- CSDN博客备份2
- CSDN 博客备份工具
- csdn博客备份脚本
- CSDN博客 专用备份工具
- CSDN博客导出备份工具
- Matlab变化检测未完成的几篇CSDN博客
- Python 安装 SQLAlchemy(未完成)
- CSDN博客专栏文章批量下载脚本[python实现]
- [Python下载CSDN博客]1. 简单实现(一)
- [Python下载CSDN博客]1. 简单实现(二)
- [Python下载CSDN博客]1. 简单实现(三)
- Python实现抓取CSDN博客首页文章列表
- HTTP协议—— 简单认识TCP/IP协议
- Android将Excel表格解析成json文件
- POJ 2993 Emag eht htiw Em Pleh(模拟)
- Listener等外部类获取Spring Bean
- URL URI 两者存在的区别
- [玩耍]Python实现备份CSDN博客(未完成)
- tensorflow 学习笔记10 网络模型的保存与提取
- 如何设计出MySQL高性能表
- [POJ 1062] 昂贵的聘礼 [最短路+枚举] [dijkstra]
- Python对内存的使用(深拷贝和浅拷贝)
- <音频编解码>
- Java面试题2:多线程与synchronized
- [LintCode]3.统计数字
- 添加Tab Control控件