from bs4 import BeautifulSoup from requests_html import HTMLSession import re url = '' assert 'https://www.ruv.is/utvarp/spila' in url with HTMLSession() as s: resp = s.get(url).html resp.render() # Run JavaScript code on webpage mp3_filename = BeautifulSoup(resp.html, 'html.parser').find('h2', {'class': 't-h2 title ls-100'}).string + '.mp3' mp3_link, *_ = re.findall('https://ruv-rod.secure.footprint.net.*?mp3', resp.html) download = s.get(mp3_link) if download.status_code == 200: print(f"Downloading link {mp3_link} into {mp3_filename}") with open(mp3_filename, 'wb') as f: f.write(download.content) else: print(f"Download Failed For File {mp3_link}")