Python网络爬虫实训:如何下载韩寒博客文章
2014-06-16 21:07
681 查看
根据智普培训视频,将抓取韩寒博客文章的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_1191258123_0_'+str(page)+'.html').read() i = 0 title = con.find(r'<a title=') href = con.find(r'href=',title) html = con.find(r'.html',href) while title != -1 and href != -1 and html != -1 and i < 50: url[i] = con[href + 6 : html + 5] print link, url[i] content = urllib.urlopen(url[i]).read() open(r'hanhan/'+url[i][-26:],'w+').write(content) print 'downloading', url[i] time.sleep(1) 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 'all find end'
相关文章推荐
- Python爬虫——下载韩寒博客文章
- [Python学习] 简单网络爬虫抓取博客文章及思想介绍
- 【python】爬虫1——下载博客文章
- 利用Python编写网络爬虫下载文章
- Python 网络爬虫 004 (编程) 如何编写一个网络爬虫,来下载(或叫:爬取)一个站点里的所有网页
- [Python学习] 简单网络爬虫抓取博客文章及思想介绍
- 利用Python编写网络爬虫下载文章
- 【Python】多线程下载韩寒博客文章
- [Python学习] 简单网络爬虫抓取博客文章及思想介绍
- Python 网络爬虫 004 (编程) 如何编写一个网络爬虫,来下载(或叫:爬取)一个站点里的所有网页
- [Python学习] 简单网络爬虫抓取博客文章及思想介绍
- 看我如何下载韩寒博客文章笔记
- 利用Python编写网络爬虫下载文章
- 【python】爬虫2——下载亦舒博客首页所有文章
- Python 网络爬虫 005 (编程) 如何编写一个可以 下载(或叫:爬取)一个网页 的网络爬虫
- Python 网络爬虫 005 (编程) 如何编写一个可以 下载(或叫:爬取)一个网页 的网络爬虫
- python实现下载韩寒博客中的所有文章,在本地存储
- 使用Python编写简单网络爬虫抓取视频下载资源
- python爬虫之python2.7.8抓取csdn博客文章
- Python 爬虫爬取指定博客的所有文章