selenium-百度新歌榜

打开百度新歌榜, http://music.baidu.com/top/new

在排名前50的歌曲中,找出其中排名上升的歌曲和演唱者

from selenium import webdriver
#chrome驱动 执行该步骤时selenium会去到指定路径将chrome driver执行起来
driver = webdriver.Chrome(r"D:\for myself\Google\Chrome\Application\chromedriver.exe")
driver.implicitly_wait(10)#隐式等待
#get方法 打开指定网址
driver.get('http://music.baidu.com/top/new')

div = driver.find_element_by_id("songListWrapper")
ul = div.find_element_by_tag_name("ul")
liList = ul.find_elements_by_tag_name('li')
for li in liList:
uptags = li.find_elements_by_class_name("up")
if uptags:
title = li.find_elements_by_class_name('song-title ')
titleStr = title.find_element_by_tag_name("a").text

authorsStr = li.find_element_by_class_name("author_list").text
print('{:10s}:{}'.format(titleStr, authorsStr))#对齐格式 宽度为10

driver.quit()

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

相关推荐