从URL下载整个文件文件夹 [英] Downloading a whole folder of files from URL
本文介绍了从URL下载整个文件文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用python3编写程序/脚本.我知道如何从URL下载单个文件,但是我需要下载整个文件夹,解压缩文件并合并文本文件.
I'm writing a program/script in python3. I know how to download single files from URL, but I need to download whole folder, unzip the files and merge text files.
是否可以将所有文件从此处下载到我的新文件夹中使用python的计算机?我正在使用urllib下载单个文件,有人可以举一个示例如何从上面的链接下载整个文件夹吗?
Is it possible to download all files FROM HERE to new folder on my computer with python? I'm using a urllib to download a single files, can anyone give a example how to download whole folder from link above?
推荐答案
安装bs4和请求,然后可以使用如下代码:
Install bs4 and requests, than you can use code like this:
import bs4
import requests
url = "http://bossa.pl/pub/metastock/ofe/sesjaofe/"
r = requests.get(url)
data = bs4.BeautifulSoup(r.text, "html.parser")
for l in data.find_all("a"):
r = requests.get(url + l["href"])
print(r.status_code)
不需要将请求的数据保存到目录中.
Than you have to save the data of the request into your directory.
这篇关于从URL下载整个文件文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文