Skip to content

Instantly share code, notes, and snippets.

@abhididdigi
Created February 16, 2014 17:47
Show Gist options
  • Save abhididdigi/9037921 to your computer and use it in GitHub Desktop.
Save abhididdigi/9037921 to your computer and use it in GitHub Desktop.
import requests;
from bs4 import BeautifulSoup
list_of_url = [];
def read_ghantasala():
url = 'http://ghantasala.info/allsongs/';
r = requests.get(url);
soup = BeautifulSoup(r.text);
for link in soup.find_all('a'):
if(link.get('href').find('mp3') > -1):
list_of_url.append(link.get('href'));
read_ghantasala();
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
print "downloaded file" + local_filename;
return local_filename
for i in list_of_url:
download_file(i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment