Last active
September 11, 2016 19:44
-
-
Save Scoppio/3bfdb4decfd63465d5bf676815fb1283 to your computer and use it in GitHub Desktop.
Download a bunch of files from somekind of "FTP" page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basically I wanted to download all the contrib modules for R present in the site... | |
# So I created this small script to do that for me. | |
from bs4 import BeautifulSoup | |
from requests import get | |
from os import path, makedirs | |
def download(url, file_name): | |
with open(file_name, "wb") as file: | |
response = get(url) | |
file.write(response.content) | |
if __name__ == "__main__": | |
download_folder = "R Packs" | |
desired_file_extension = ".zip" | |
if not path.exists(download_folder): | |
makedirs(download_folder) | |
url = "http://nbcgib.uesc.br/mirrors/cran/bin/windows/contrib/3.4/" | |
result = get(url) | |
result = result.content | |
soup = BeautifulSoup(result, "lxml") | |
for link in soup.find_all('a'): | |
a = link.get('href') | |
if desired_file_extension in a: | |
if not path.isfile( path.join(download_folder,a)): | |
print(a) | |
download(url+a, path.join(download_folder,a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment