如果班上只有一个角色,它就抓不住了。我只是简单地说,一旦得到了歌曲的标题,艺术家就会在下一首歌中跟进
<span>
标签明白了吗
<h3>
像你为歌曲做的那样标记,然后使用
.find_next()
要获得艺术家:
import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.billboard.com/charts/hot-100/')
soup = BeautifulSoup(r.content, 'html.parser')
result = soup.find_all('div', class_='o-chart-results-list-row-container')
for res in result:
songName = res.find('h3').text.strip()
artist = res.find('h3').find_next('span').text.strip()
print("song: "+songName)
print("artist: "+ str(artist))
print("___________________________________________________")
输出:
song: Heat Waves
artist: Glass Animals
___________________________________________________
song: Stay
artist: The Kid LAROI & Justin Bieber
___________________________________________________
song: Super Gremlin
artist: Kodak Black
___________________________________________________
song: abcdefu
artist: GAYLE
___________________________________________________
song: Ghost
artist: Justin Bieber
___________________________________________________
song: We Don't Talk About Bruno
artist: Carolina Gaitan, Mauro Castillo, Adassa, Rhenzy Feliz, Diane Guerrero, Stephanie Beatriz & Encanto Cast
___________________________________________________
song: Enemy
artist: Imagine Dragons X JID
___________________________________________________
....