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

Time:01-10

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

CodePudding user response:

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's the weather today?")
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's the weather today\?
  • Related