I
I
I_am_Human2021-12-05 17:39:26
Python
I_am_Human, 2021-12-05 17:39:26

How to download mp3 using requests and python?

Hello! How can I download an mp3 file from this site https://r.megapesni.me/rap_2018/140731-miyagi-capt... using requests? Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-12-05
@I_am_Human

import requests
from bs4 import BeautifulSoup

host = 'https://megapesni.club'
link = 'https://megapesni.club/rap_2018/140731-miyagi-captain.html'

headers = {'user-agent':'Hottabxp - Cool Hacker!'}

response = requests.get(link, headers=headers)

soup = BeautifulSoup(response.text,'html.parser')
song_title = soup.find('h1',class_='music-title').text
url = soup.find('a',class_='song-author-btn song-author-btn--download').get('href')

response = requests.get(host+url,headers=headers)
with open(song_title+'.mp3','wb') as mp3:
  mp3.write(response.content)

Python is the world's easiest tool for parsing and downloading files. And this is a fact!
Beautiful Soup in Russian
Requests: HTTP for Humans™

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question