### -*- coding: cp936 -*-
###<a href="http://home.51cto.com" target="_blank">家园</a>
##import urllib
##str0='<a href="http://home.51cto.com" target="_blank">家园</a>'
##href=str0.find('<a href')
##print href
##com=str0.find('.com"')
##print com
##url=str0[href+9:com+4]
##print url
##content=urllib.urlopen(url).read()
###print content
##filename=url[-9:]
##print filename
##open(filename,'w').write(content)
####_________________________________
import urllib
url = ['']*50
con = urllib.urlopen('http://blog.sina.com.cn/s/articlelist_1191258123_0_1.html').read()
i = 0
title = con.find(r'<a title=')
href = con.find('href=',title)
html = con.find('.html',href)
while title !=-1 and href != -1 and html != -1 and i < 50 :
url[i] = con[href + 6:html + 5]
print url[i]
title = con.find('<a title=',html)
href = con.find('href=',title)
html = con.find('.html',href)
i = i + 1
else:
print 'find end!'
j = 0
while j < 50:
content = urllib.urlopen(url[j]).read()
open('hanhan/'+url[j][-26:],'w').write(content)
j = j + 1
else:
print "over"
##
##--------------------------------------------
网页抓取
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
注册个博来保存一些文章
zinejo
2019-02-23 13:50:47
菜鸟创建优秀网页的6个好习惯.
verytt
2019-02-23 13:40:45
学习随笔--网页(表单框架模板等)
瓦蘭
2019-02-23 13:19:08
IE无法打开网页的常见原因及解决!
zorro8106
2019-02-23 12:52:59
(JQuery学习笔记)利用jquery制作网页导航定位
w1sw
2019-02-23 00:33:03
iframe里面内容自动跳转问题解决办法
wjj8899867
2019-02-23 00:29:40
JS module的导出和导入
KevinYan
2019-02-24 21:34:55
Java-第六章-用for和if-elseif 完整了用户登录信息验证
瘋子偉偉
2019-02-23 00:42:42
二维码生成
StringLong
2019-02-23 00:41:58
android 控件跟随手指移动
huangwenwenlili
2019-02-23 00:41:23
JAVA中获取当前系统时间,日期并格式化输出
kb85192363
2019-02-23 00:17:46