Skip to content

Instantly share code, notes, and snippets.

@LuRsT
Created April 12, 2013 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuRsT/5372033 to your computer and use it in GitHub Desktop.
Save LuRsT/5372033 to your computer and use it in GitHub Desktop.
Script to save .cue and .mp3 files from webpages, receives the url as first argument.
import sys
from bs4 import BeautifulSoup
import requests
import urllib
try:
r = requests.get(sys.argv[1])
if r.status_code != 200:
exit('Page not found')
except:
raise
soup = BeautifulSoup(r.text)
links = soup.find_all('a')
for a in links:
href = a.get('href')
if href.endswith(('.mp3', '.cue')):
url = a.get('href')
print "Downloading: %s" % url
print "File output: %s\n" % urllib.unquote(url.split('/')[-1])
print "Saving..."
file = requests.get(url)
output = open(urllib.unquote(url.split('/')[-1]), 'wb')
output.write(file.content)
output.close()
@LuRsT
Copy link
Author

LuRsT commented Apr 12, 2013

Requirements:

  • BeautifulSoup4
  • requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment