Python项目实战之下载博客文章
2017-01-18 21:00
561 查看
1.打开博客列表首页
http://blog.sina.com.cn/s/articlelist_6053900192_0_1.html
目标:捕获所有文章的超链接
2. 博客文章列表特征
<a title=… href=… .html>
3. 技术要点
字符串函数find
列表list[-x:-y]
文件读写操作
循环体while
4. 实现步骤
能够在浏览器里打开韩寒博客文章列表首页的博客网页
从首页网页里获得博客上的所有文章链接
所有文章列表网页里的文章链接
下载所有链接html文件、
5. python
http://blog.sina.com.cn/s/articlelist_6053900192_0_1.html
目标:捕获所有文章的超链接
2. 博客文章列表特征
<a title=… href=… .html>
3. 技术要点
字符串函数find
列表list[-x:-y]
文件读写操作
循环体while
4. 实现步骤
能够在浏览器里打开韩寒博客文章列表首页的博客网页
从首页网页里获得博客上的所有文章链接
所有文章列表网页里的文章链接
下载所有链接html文件、
5. python
#coding:utf-8 import urllib import time url=['']*350 page=1 link =1 while page <=7: con=urllib.urlopen('http://blog.sina.com.cn/s/articlelist_1259295385_0_'+str(page)+'.html').read() #print 'con', con i=0 title=con.find(r'<a title=') #print title href=con.find(r'href=', title) #print href html=con.find(r'.html', href) #print html print url while title != -1 and href != -1 and html != -1 and i < 350: url[i]=con[href + 6:html + 5] print link,' ',url[i] title=con.find(r'<a title=', html) href=con.find(r'href=', title) html=con.find(r'.html', href) i=i+1 link=link + 1 else: print page, 'find end!' page=page + 1 else: print 'find end' j=0 while j <350: content=urllib.urlopen(url[j]).read() open(r'xiongpan/'+url[j][-26:], 'w+').write(content) print 'downloading', url[j] j=j + 1 time.sleep(15) else: print 'download article finished'
相关文章推荐
- 【python】爬虫2——下载亦舒博客首页所有文章
- python_爬取博客文章下载到本地
- 【Python】多线程下载韩寒博客文章
- 【实战\聚焦Python分布式爬虫必学框架Scrapy 打造搜索引擎项目笔记】第4章 scrapy爬取知名技术文章网站(2)
- Python实战项目之博客网站搭建
- Python项目实战:个人博客(1)
- 人脸检测和识别 源代码 下载-opencv3+python3.6完整实战项目源代码 识别视频《欢乐颂》中人物
- python实现文章或博客的自动摘要(附java版开源项目)
- CSDN博客专栏文章批量下载脚本[python实现]
- Python项目实战:个人博客(2):搭建orm框架
- 小兔博客新增源码下载模块,JavaWeb项目实战,JavaScript入门教程 ,JavaSE案例等
- python实现下载韩寒博客中的所有文章,在本地存储
- python下载QQ空间的博客文章
- 下载大数据实战课程第二季基于Python机器学习、项目案例实战
- Python3 大型网络爬虫实战 002 --- scrapy 爬虫项目的创建及爬虫的创建 --- 实例:爬取百度标题和CSDN博客
- Python爬虫——下载韩寒博客文章
- 一个简单的python网络爬虫程序(下载博客文章)
- 【python】爬虫1——下载博客文章
- CSDN博客专栏文章批量下载脚本[python实现]
- Python网络爬虫实训:如何下载韩寒博客文章