简体   繁体   English

解析Python中的post请求

[英]Parse post request in Python

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 https://top-radio.ru/web/marusya-fm

The name of the song included in歌曲名称包含在动图格式from POST string来自 POST 字符串

输出, that I have , 我有

How I can parse this case?我该如何解析这个案例?

This site uses java script.本站使用java脚本。 Beautiful soup is not enough for this.漂亮的汤还不够。 Use Selenium for such a task.使用 Selenium 来完成这样的任务。 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: https://selenium-python.readthedocs.io/在这里您可以下载 Firefox 的 geckodriver。 https://github.com/mozilla/geckodriver/releases然后将这些行添加到您的代码中:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM