Reputation: 1
Good day! I have trouble with parsing dynamic element from radio stations website. Here you need the name of the current song
import requests
from bs4 import BeautifulSoup
songsNameList = []
url = f"https://top-radio.ru/web/russkij-xit"
q = requests.get(url)
result = q.content
soup = BeautifulSoup(result, 'lxml')
songs = soup.select("#se_igra")
for song in songs:
print(song.find('span'))
songsNameList.append(song.find('span'))
https://top-radio.ru/web/marusya-fm
The name of the song included in from POST string
, that I have
How I can parse this case?
Upvotes: 0
Views: 94
Reputation: 21
This site uses java script. Beautiful soup is not enough for this. Use Selenium for such a task. You can read more here. https://selenium-python.readthedocs.io/ Here you can download geckodriver for Firefox. https://github.com/mozilla/geckodriver/releases Then add to your code these lines:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
binary = FirefoxBinary(r'/usr/bin/firefox') #add here in quotes path to your Firefox
caps = DesiredCapabilities.FIREFOX.copy()
caps['marionette'] = True
driver = webdriver.Firefox(firefox_binary=binary, capabilities=caps, firefox_profile=profile,
executable_path='/usr/bin/geckodriver') ##add here in quotes path to downloaded geckodriver
q = driver.get(url)
Upvotes: 1