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()

posted on 2019-06-28 16:28  芋头加满仓  阅读(227)  评论(0编辑  收藏  举报

导航