urllib下载在线目录的内容

urllib下载在线目录的内容,第1张

urllib下载在线目录的内容

这段代码对我有用。我只是对其进行了一点修改,因为您正在复制每个ppt文件。

from urllib2 import urlopenimport reurlpath =urlopen('http://www.divms.uiowa.edu/~jni/courses/ProgrammignInCobol/presentation/')string = urlpath.read().depre('utf-8')pattern = re.compile('ch[0-9]*.ppt"') #the pattern actually creates duplicates in the listfilelist = pattern.findall(string)print(filelist)for filename in filelist:    filename=filename[:-1]    remotefile = urlopen('http://www.divms.uiowa.edu/~jni/courses/ProgrammignInCobol/presentation/' + filename)    localfile = open(filename,'wb')    localfile.write(remotefile.read())    localfile.close()    remotefile.close()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5631654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存