Python爬取韩寒所有新浪博客
接上一篇,我们依据第一页的链接爬取了第一页的博客,我们不难发现,每一页的链接就仅仅有一处不同(页码序号),我们仅仅要在上一篇的代码外面加一个循环,这样就能够爬取全部博客分页的博文。也就是全部博文了。
# -*- 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爬取韩寒所有新浪博客的更多相关文章
- Python爬虫爬取一篇韩寒新浪博客
网上看到大神对Python爬虫爬到非常多实用的信息,认为非常厉害.突然对想学Python爬虫,尽管自己没学过Python.但在网上找了一些资料看了一下,看到爬取韩寒新浪博客的视频.共三集,第一节讲爬取 ...
- python网络爬虫 新浪博客篇
上次写了一个爬世纪佳缘的爬虫之后,今天再接再厉又写了一个新浪博客的爬虫.写完之后,我想了一会儿,要不要在博客园里面写个帖子记录一下,因为我觉得这份代码的含金量确实太低,有点炒冷饭的嫌疑,就是把上次的代 ...
- python中multiprocessing.pool函数介绍_正在拉磨_新浪博客
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客 python中multiprocessing.pool函数介绍 (2010-06-10 03:46:5 ...
- python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客
python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客 python datetime模块strptime/strptime form ...
- python中逐行读取文件的最佳方式_Drupal_新浪博客
python中逐行读取文件的最佳方式_Drupal_新浪博客 python中逐行读取文件的最佳方式 (2010-08-18 15:59:28) 转载▼ 标签: python ...
- python—webshell_醉清风xf_新浪博客
python—webshell_醉清风xf_新浪博客 python—webshell (2012-05-23 09:55:46) 转载▼
- Javascript Jquery 中的数组定义与操作_子木玲_新浪博客
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- 关于Windows文件读写_暗涌_新浪博客
关于Windows文件读写_暗涌_新浪博客 这几天在研究怎么才能加快windows文件读写速度,搜了很多文章,MSDN也看了不少.稍微给大家分享一下. 限制windows文件读写速度的 ...
- MWeb 1.3.7 发布!增加发布到 Wordpress 等支持 MetaWeblog API 的服务,如:Wordpress 博客、新浪博客、cnblogs、oschina。
MWeb 1.3.7 版的新功能 增加发布到 Wordpress 等支持 Metaweblog API 的服务,目前经测试过的有: Wordpress 博客.新浪博客.cnblogs.oschina. ...
随机推荐
- PHP-redis命令之 散列(hashes)
二.散列(hashes) 1.hset:设置散列的值 $redis->hset('myhas','field1','hello'); $redis->hset('myhas','field ...
- Linux下二进制文件安装MySQL
MySQL 下载地址:https://dev.mysql.com/downloads/mysql/ 并按如下方式选择来下载安装包. 1. 设置配置文件/etc/my.cnmore /etc/my.cn ...
- Arthas诊断工具使用资料
1.https://github.com/alibaba/arthas/issues/327 2.https://alibaba.github.io/arthas/jad.html 3.https:/ ...
- js--如何判别 null undefined
收集资料如下判断: 1.判断undefined: ? 1 2 3 4 var tmp = undefined; if (typeof(tmp) == "undefined"){ a ...
- ubuntu介绍以及使用
Ubuntu(友帮拓.优般图.乌班图)是一个以桌面应用为主的开源GNU/Linux操作系统,Ubuntu 是基于Debian GNU/Linux,支持x86.amd64(即x64)和ppc架构,由全球 ...
- 解决wordpress部分博客文章页面无法显示的问题
搭建完wordpress,试着写了一篇博客.文章发布后,首页已经能显示出文章的标题,但是点进去后却提示该页无法显示. 百度一番,先后尝试网上的修改apache配置等方法后依然无效.折腾到最后无意间发现 ...
- offset家族
- 【leetcode最短路】818. Race Car
https://leetcode.com/problems/race-car/description/ 1. BFS剪枝 0<=current position<=2*target.为什么 ...
- spring aop在mvc的controller中加入切面无效
spring aop在mvc的controller中加入切面无效 因为MVC的controller,aop默认使用jdk代理.要使用cglib代理. 在spring-mybatis.xml配置文件中加 ...
- 转 Linux中常用操作命令
http://blog.csdn.net/ljianhui/article/details/11100625 初窥Linux 之 我最常用的20条命令 玩过Linux的人都会知道,Linux中的命令的 ...