代码笔记 | 自动爬取百度贴吧的网页

 
import string,urllib2
def baidu(url,bp,ep):
    for i in range(bp,ep+1):
        sName=string.zfill(i,5)+'.html'
        print 'Download' + str(i) + 'page,store named' + sName + '......'
        f=open(sName,'w+')
        m=urllib2.urlopen(url+str(i)).read()
        f.write(m)
        f.close()
bdurl=str(raw_input(u'Please input the url, cut the number:\\n'))
bp=int(raw_input(u'Plase input the start page:\\n'))
ep=int(raw_input(u'Plase input the end page:\\n'))
  
baidu(bdurl,bp,ep)

你可能感兴趣的:(python,代码笔记)