user5490674
user5490674

Reputation:

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?

Upvotes: 4

Views: 14089

Answers (1)

MegaIng
MegaIng

Reputation: 7886

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.

Upvotes: 6

Related Questions