接上一篇,我们依据第一页的链接爬取了第一页的博客,我们不难发现,每一页的链接就仅仅有一处不同(页码序号),我们仅仅要在上一篇的代码外面加一个循环,这样就能够爬取全部博客分页的博文。也就是全部博文了。

# -*- coding : -utf-8 -*-
import urllib
import time
url = [' ']*350
page = 1
link = 1
while page <=7://眼下共同拥有7页。3
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<350:
url[i] = con[href + 6:html + 5] content = urllib.urlopen(url[i]).read()
open(r'allboke/'+url[i][-26:],'w+').write(content) print 'link',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',page,'find end!'
page = page + 1
else:
print 'all find end' #i = 0
#while i < 350:
#content = urllib.urlopen(url[i]).read()
#open(r'save/'+url[i][-26:],'w+').write(content)
#print 'downloading',i,url[i]
#i = i + 1
#time.sleep(1)
#else:
print 'download artical finished!'

代码最以下部分,保存网页仅仅能保存到50,不知道错在哪里。

所以就将保存网页的代码放在搜索里,找到就保存!

正确执行界面:

执行结果:

Python爬取韩寒所有新浪博客的更多相关文章

  1. Python爬虫爬取一篇韩寒新浪博客

    网上看到大神对Python爬虫爬到非常多实用的信息,认为非常厉害.突然对想学Python爬虫,尽管自己没学过Python.但在网上找了一些资料看了一下,看到爬取韩寒新浪博客的视频.共三集,第一节讲爬取 ...

  2. python网络爬虫 新浪博客篇

    上次写了一个爬世纪佳缘的爬虫之后,今天再接再厉又写了一个新浪博客的爬虫.写完之后,我想了一会儿,要不要在博客园里面写个帖子记录一下,因为我觉得这份代码的含金量确实太低,有点炒冷饭的嫌疑,就是把上次的代 ...

  3. python中multiprocessing.pool函数介绍_正在拉磨_新浪博客

    python中multiprocessing.pool函数介绍_正在拉磨_新浪博客     python中multiprocessing.pool函数介绍    (2010-06-10 03:46:5 ...

  4. python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客

    python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客     python datetime模块strptime/strptime form ...

  5. python中逐行读取文件的最佳方式_Drupal_新浪博客

    python中逐行读取文件的最佳方式_Drupal_新浪博客 python中逐行读取文件的最佳方式    (2010-08-18 15:59:28)    转载▼    标签:    python   ...

  6. python—webshell_醉清风xf_新浪博客

    python—webshell_醉清风xf_新浪博客 python—webshell (2012-05-23 09:55:46) 转载▼

  7. Javascript Jquery 中的数组定义与操作_子木玲_新浪博客

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  8. 关于Windows文件读写_暗涌_新浪博客

    关于Windows文件读写_暗涌_新浪博客     这几天在研究怎么才能加快windows文件读写速度,搜了很多文章,MSDN也看了不少.稍微给大家分享一下.     限制windows文件读写速度的 ...

  9. MWeb 1.3.7 发布!增加发布到 Wordpress 等支持 MetaWeblog API 的服务,如:Wordpress 博客、新浪博客、cnblogs、oschina。

    MWeb 1.3.7 版的新功能 增加发布到 Wordpress 等支持 Metaweblog API 的服务,目前经测试过的有: Wordpress 博客.新浪博客.cnblogs.oschina. ...

随机推荐

  1. 【20】display,float,position的关系

    [20]display,float,position的关系 如果display为none,元素不显示. 否则,如果position值为absolute或者fixed,元素绝对定位,float的计算值为 ...

  2. 大数据学习——Storm+Kafka+Redis整合

    1 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  3. PTA 08-图9 关键活动 (30分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/719 假定一个工程项目由一组子任务构成,子任务之间有的可以并行执行,有的必须在完成了其它 ...

  4. 转载:C++读取特定路径下文件目录及文件名称

    转载地址:http://www.cnblogs.com/tgyf/p/3839894.html void getAllFiles( string path, vector<string>& ...

  5. 【bzoj2393】Cirno的完美算数教室 数论容斥

    Description ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~ 现在Cirno想知道~一个区间中~~有多少个数能被baka数整除~ 但是Cirno这么天才的妖精才不屑去数 ...

  6. LightOJ1125 Divisible Group Sums

    Divisible Group Sums Given a list of N numbers you will be allowed to choose any M of them. So you c ...

  7. 服务器内部转发forward,action到action

    如果request.getRequestDispatcher();中不是页面而是传action的话,参考以下内容修改: web.xml 2.4版本里,默认的filter只拦截request. 如果使用 ...

  8. selenium 与 firefox版本不兼容报错

    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 ...

  9. JSP表单提交中文乱码

    简要笔记:由于jsp默认表单提交编码方式是:ISO-8859-1,而我们需要的是utf-8或者是gbk码,故需要转化. 具体方法是:在表单处理文件中,将获取到的变量进行转换. String userN ...

  10. POJ 3104 Drying [二分 有坑点 好题]

    传送门 表示又是神题一道 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9327   Accepted: 23 ...