码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-01-12 14:33:56      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

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(r‘href="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(r‘href="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)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!