Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
python sript to grab .mp3 url from a html page/ web page
from bs4 import BeautifulSoup
import os
import urllib.request as urllib2
except ImportError:
import urllib2
import sys
#Souce html from which the you want stuff to download
source_url = ""
#write url as text file to download it with Aria2c downloader, remember to make it in aria2c folder and create the fil urls.txt
aria2c_filepath = "C:/Users/User2/Desktop/aria2-1.28.0-win-64bit-build1/urls.txt"
html_page = urllib2.urlopen(source_url)
soup = BeautifulSoup(html_page)
#print All links in the html pages, i used for my first execution to analyse the url and write the rule for it.
for all_links in soup.findAll('a'):
the_url = all_links.get('href')
print(the_url) '''
#Deleting existing contents from the file
f = open(aria2c_filepath, 'w')
for link in soup.findAll('a'):
temp_reader = link.get('href')
if(".mp3?l=12" in temp_reader):
url = (""+temp_reader).split("?l=12")[0];
with open(aria2c_filepath, 'a') as f:
print(url, file=f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.