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‘)
时间: 2024-11-08 10:49:12