SoFunction
Updated on 2024-12-20

Python implementation of the batch download RFC documents

def downloadHtmlPage(url,tmpf = ''):
    i = ('/')
    fileName = url[i+1:]
    if tmpf : fileName = tmpf
    print url,"->",fileName
    (url,fileName)
    print 'Downloaded ',fileName   
    (0.2)
    return fileName
   
# /enp/rfc/
# /enp/rfc/
if __name__ == '__main__':
    addr = '/enp/rfc'   
    dirPath = "RFC"
    #startIndex = 1000
    startIndex = int(raw_input('start : '))
    #endIndex = 6409
    endIndex = int(raw_input('end : '))
    if startIndex > endIndex :
        print 'Input error!'       
    if False == (dirPath):
        (dirPath)   
    fileDownloadList = []
    logFile = open("","w")
    for i in range(startIndex,endIndex+1):
        try:           
            t_url = '%s/rfc%' % (addr,i)
            fileName = downloadHtmlPage(t_url)
            oldName = './'+fileName
            newName = './'+dirPath+'/'+fileName
            if True == (oldName):
                (oldName,newName)
                print 'Moved ',oldName,' to ',newName
        except:
            msgLog = 'get %s failed!' % (i)
            print msgLog
            (msgLog+'\n')
            continue
    ()