python 怎么下载网站文件夹下的所有文件 python 怎么获取路径下的所有文件

python\u600e\u4e48\u67e5\u6587\u4ef6\u5939\u4e0b\u6240\u6709\u6587\u4ef6

import os
import os.path
rootdir = \u201cd:\data\u201d # \u6307\u660e\u88ab\u904d\u5386\u7684\u6587\u4ef6\u5939
for parent,dirnames,filenames in os.walk(rootdir): #\u4e09\u4e2a\u53c2\u6570\uff1a\u5206\u522b\u8fd4\u56de1.\u7236\u76ee\u5f55 2.\u6240\u6709\u6587\u4ef6\u5939\u540d\u5b57\uff08\u4e0d\u542b\u8def\u5f84\uff09 3.\u6240\u6709\u6587\u4ef6\u540d\u5b57
for dirname in dirnames: #\u8f93\u51fa\u6587\u4ef6\u5939\u4fe1\u606f
print "parent is:" + parent
print "dirname is:" + dirname
for filename in filenames: #\u8f93\u51fa\u6587\u4ef6\u4fe1\u606f
print "parent is:" + parent
print "filename is:" + filename
print "the full name of the file is:" + os.path.join(parent,filename) #\u8f93\u51fa\u6587\u4ef6\u8def\u5f84\u4fe1\u606f

#\u53ef\u4ee5\u4f7f\u7528os.listdir()
import os#\u6307\u5b9a\u7684\u76ee\u5f55path = "/xxxx/xx/"filelist = []for f in os.listdir(): if os.path.isdir(f): filelist.append(f)#\u6253\u5370\u51fa\u6240\u6709\u6587\u4ef6\u7684\u5217\u8868 print filelist

第一步:
必须知道有哪些文件。
第二步:
知道路径就可以使用urlretrieve函数保存了。

但是第一步你不说背景很难啊。
是网页的话,可能那个需要简单解析一下网页就行了,有list dir权限更方便,直接ls就行,穷举是估计不行的,谁知道文件路径长度?

扩展阅读:python手机版下载官方 ... photoshop永久免费版 ... python解释器手机版下载 ... python3.6下载官网 ... photoshop免费网站入口 ... python登录网站下载数据 ... python编程免费网站 ... python官网入口下载 ... qpython官网下载 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网