【问题标题】:Trying to figure out why BS returns an empty list试图弄清楚为什么 BS 返回一个空列表
【发布时间】:2021-01-09 03:09:56
【问题描述】:

我对此很陌生,所以请原谅我。我尝试使用 BeautifulSoupSpotify 播放列表中提取歌曲名称,但遇到了问题。当我尝试搜索我想要的标签时,我什么也得不到。

from bs4 import BeautifulSoup
import requests

result = requests.get('https://open.spotify.com/playlist/6UeSakyzhiEt4NB3UAd6NQ')
src = result.content
soup = BeautifulSoup(src, 'lxml')

songs = soup.findAll("div", {"role":"row"})

print (songs)

【问题讨论】:

  • 如果你喜欢这个答案,请接受它并投票 thx

标签: python web-scraping beautifulsoup


【解决方案1】:

你必须分析 hmtl 才能找到你想要的更好的东西:下面为你提供歌曲名称...

from bs4 import BeautifulSoup
import requests

result = requests.get('https://open.spotify.com/playlist/6UeSakyzhiEt4NB3UAd6NQ')
src = result.content
soup = BeautifulSoup(src, 'lxml')

songs = soup.findAll("span", {"class":"track-name"})

for song in songs:
    print(''.join(song.findAll(text=True))+'\n')

【讨论】:

  • 我会删除我的,因为你赌我几秒钟。我也会支持你的。
  • 哇...感谢您的体育精神,谢谢
猜你喜欢
  • 2020-08-14
  • 1970-01-01
  • 2015-04-06
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多