Home > Net >  Extract audio URL (mp3) from web player using Python
Extract audio URL (mp3) from web player using Python

Time:03-29

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'

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?

CodePudding user response:

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")
  • Related