Skip to content

Instantly share code, notes, and snippets.

@mehedithedue
Created November 14, 2019 10:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehedithedue/92b07c0bd365b6cad4c84a664d1a065d to your computer and use it in GitHub Desktop.
Save mehedithedue/92b07c0bd365b6cad4c84a664d1a065d to your computer and use it in GitHub Desktop.
Download all mp4 file from a url and save in destination folder by Python
from bs4 import BeautifulSoup
import wget
import requests
import os
url = 'http://canvas.projekti.info/laracast/%20Intermediate%20Laravel/'
ext = 'mp4'
destinationFolder = "/home/mehedi/Downloads/intermediate_laravel/"
def getAllPaths(page, ext) :
fileUrl = []
page = requests.get(url).text
soup = BeautifulSoup(page, 'html.parser')
for node in soup.find_all('a'):
if(node.get('href').endswith(ext)) :
fileUrl.append(node.get('href'))
return fileUrl
def downloadFile(downloadlink, fileName):
with requests.get(downloadlink, stream=True) as r:
r.raise_for_status()
filePath = os.path.join(destinationFolder, fileName)
print("Downloading to", os.path.abspath(filePath))
with open(filePath, 'wb') as f:
for chunk in r.iter_content(chunk_size=8 * 1024):
if chunk:
f.write(chunk)
f.flush()
f.close()
result = getAllPaths(url, ext)
for fileName in result :
downloadFile(url+fileName, fileName)
print(fileName + " Downloaded")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment