selenium - qq音乐排名
打开qq音乐, https://y.qq.com/n/yqq/toplist/27.html#stat=y_new.toplist.menu.27
找出其中排名上升的歌曲和演唱者
最终结果显示的结果如下:
孤独 : G.E.M. 邓紫棋
Lovesick Girls : BLACKPINK
落幕人 : 任然
幸存者 : 林俊杰
刁钻 : 任然
注意:界面有时会弹出广告框,可以先手动关闭掉,防止其影响自动化爬取信息
代码
点击查看代码
from selenium import webdriver
# 创建 WebDriver
wd = webdriver.Chrome(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
wd.implicitly_wait(10)
# 打开指定网址
wd.get(' https://y.qq.com/n/yqq/toplist/27.html#stat=y_new.toplist.menu.27')
# 歌曲部分 ul
songlist = wd.find_element_by_class_name('songlist__list')
# 每一首歌曲 取出所有 li
songs = songlist.find_elements_by_tag_name('li')
# 遍历每个 li
for song in songs:
rank = song.find_element_by_class_name('songlist__rank')
icon = rank.find_element_by_tag_name('i')
# print(icon.get_attribute('class'))
if icon.get_attribute('class') == 'icon_rank_up':
# sn = song.find_element_by_class_name('songlist__cover')
# songname =sn.get_attribute('title')
# print(songname)
# 歌曲名
sn = song.find_element_by_class_name('songlist__songname_txt')
info = sn.find_elements_by_tag_name('a')
songname = info[1].get_attribute('title')
# 作者
sa = song.find_element_by_class_name('playlist__author')
author = sa.get_attribute('title')
# print(author)
print(f'{songname:20}: {author}')

浙公网安备 33010602011771号