微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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}')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐