I want to download and save the audio of the link in python

Question:

I want to download and save the audio of the link in python.
How should I write it in beautifulsoup or selenium?
I don’t know the answer.

Link

Asked By: Jun K.

||

Answers:

If you want to download something with Python, there is no reason to use either Selenium or BeautifulSoup. Instead, consider using the requests library:

pip install requests

And download the mp3 like so:

import requests

response = requests.get("https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=how%27s%20the%20weather%20today?")
open("file.mp3", "wb").write(response.content)

This will download the audio to a file called file.mp3 in your local directory.

You could also use other alternatrives such as wget and urllib. You could even download the file by running a simple curl command:

curl -o file.mp3 https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=how%27s%20the%20weather%20today?
Answered By: M B
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.