Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading a whole folder of files from 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.

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?


1 Answers

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.

like image 99
MegaIng Avatar answered Sep 08 '25 11:09

MegaIng