Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract audio URL (mp3) from web player using Python

I am trying to extract URL link from webpage so I could download the audio as mp3, but still unsuccess… Here is a webpage code:

webpage code

I would like to grab a value of ‘scr’ attribute: https://radio-arch-pp.stv.livebox.sk/a520/00/0024/002424/00242487-1.mp3’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

None of these attempts prints that value:

1)

import requests
from bs4 import BeautifulSoup

re  = requests.get("https://www.rtvs.sk/embed/audio/242500")
soup = BeautifulSoup(re.text, 'html.parser')

result = soup.findAll("div", id="player_audio_242500")
print(result)

for n in soup.findAll("div", id="player_audio_242500"):
    if 'src' in n.attrs:
        result = n['src']
    else:
        result = n.text
    print(result)

for n in soup.find_all('script'):
    print(n.get('src'))

for n in soup.find_all('script'):
    if 'src' in n.attrs:
        result = n['src']
    else:
        result = n.text
    print(result)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service

ser = Service("chromedriver")
op = webdriver.ChromeOptions()
chrome_browser = webdriver.Chrome(service=ser, options=op)
chrome_browser.maximize_window()
chrome_browser.get('https://www.rtvs.sk/embed/audio/242500')

enter = chrome_browser.find_element(by=By.CSS_SELECTOR, value="[id^=player_audio]")
print(enter)
print(enter.text)

Can anybody help please?

>Solution :

Take a look at your css selector, it should select the video and should take its src attribute like that:

chrome_browser.find_element(By.CSS_SELECTOR, 'video').get_attribute("src")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading