【问题标题】:Parse post request in Python在 Python 中解析 post 请求
【发布时间】:2021-08-14 23:25:09
【问题描述】:

美好的一天!我无法从广播电台网站解析动态元素。这里需要当前歌曲的名称

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

POST 字符串中 中包含的歌曲名称

,我有

我该如何解析这个案例?

【问题讨论】:

    标签: python html http parsing


    【解决方案1】:

    本站使用java脚本。漂亮的汤是不够的。使用 Selenium 来完成这样的任务。 你可以在这里阅读更多。 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)
    

    【讨论】:

    • 谢谢你的这种方式。曾经在其他项目中使用浏览器驱动程序求解时,此应用程序未在 docker-compose、nginx 和远程源中加载。是否有针对该方向的更分离、更有效和更紧密的步骤进行无人驾驶解析的解决方案?
    • 你可以无头使用它
    • 译者给我们惊喜。我将 FirefoxProfile 字符串添加到代码中。启动后,应用不发送当前歌曲
    • profile = FirefoxProfile("/home/ilya/.mozilla/firefox/")print(q) Output: None
    • profile = webdriver.FirefoxProfile() 或者根本不使用配置文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2014-01-01
    相关资源
    最近更新 更多