I
I
IUniner2021-08-14 18:34:53
Python
IUniner, 2021-08-14 18:34:53

What is the Python way to Parse a dynamic element from a POST request to a website?

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'))


From the site you need to get the data of the current composition. In the request overview, this data comes in the form of a response in gif format and is displayed only in the browser. How to render a page without using the browser engine?
The pictures show the result of the code and the post-request from the site.

6117e10a4fe05871156586.png
6117e11323300180192258.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2021-08-14
@IUniner

As you can see on the site, the current song is obtained by a websocket connection and an ajax request to get the "What's playing now" column. If you want to get the song that is currently playing, you can make an ajax request to https://top-radio.ru/ajax , sending the request body from the site + getting the id from the page, and parsing the result: 6117e670db85b834120431.png
If you want to receive information about the update in real time via websockets, connecting to wss://ws.auto-messenger.ru/app/123124 , specifying the name of the radio as the first message, you can use the "websockets" python library:
6117e6a6d93f3348074976.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question