抓取网页链接,并保存到本地

时间:2015-01-12 14:31:51   收藏:0   阅读:292
import urllib2
import urllib

content=urllib2.urlopen("http://www.cnblogs.com/sayary/archive/2013/03/11/2952638.html").read()
##print content

##<a title="发布于2013-03-10 13:53"
##href="http://www.cnblogs.com/sayary/archive/2013/03/10/2952640.html">


href=content.find(rhref="http://www.cnblogs.com/sayary/archive)
end=content.find(r.html)
print href
print end

url=content[href+6:end+5]
print url




str2=content.find(rhref="http://www.cnblogs.com/sayary/archive,end)
end2=content.find(r.html,str2)

print str2
print end2

url2=content[str2+6:end2+5]

print url2
urllib.urlretrieve(url, 1.html)
urllib.urlretrieve(url2, 2.html)

 

 

原文:http://www.cnblogs.com/xinshijie/p/4218232.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!