Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created June 29, 2018 15:50
Show Gist options
  • Save blackknight36/40e0c1903abcab18b5de49793db06531 to your computer and use it in GitHub Desktop.
Save blackknight36/40e0c1903abcab18b5de49793db06531 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# This script requires the BeautifulSoup module and python-requests to work
import requests, sys
from bs4 import BeautifulSoup
def download_file(file_url):
local_filename = file_url.split('/')[-1]
r = requests.get(file_url, stream=True)
with open(local_filename, 'wb') as fd:
for chunk in r.iter_content(chunk_size=128):
fd.write(chunk)
if len(sys.argv) < 2:
print("Please enter a URL to download files from.")
exit(1)
else:
site_url = sys.argv[1]
soup = BeautifulSoup(requests.get(site_url).text, "lxml")
for a in soup.find_all('a'):
if 'm4a' in a['href'] or 'mp3' in a['href']:
file_url = site_url + '/' + a['href']
print(file_url)
download_file(file_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment