Selenium学习笔记||六、练习(查上升歌曲)
# 打开百度新歌榜, http: // music.baidu.com / top / new在排名前50的歌曲中,找出其中排名上升的歌曲和演唱者
#
# 注意: 有的歌曲名里面有"影视原声"这样的标签, 要去掉
#
# 最终结果显示的结果如下:
# 我不能忘记你: 林忆莲
# 等: 严艺丹
from selenium import webdriver driver = webdriver.Chrome(r"D:\webdriver\chromedriver_73.0.3683.68.exe") driver.get("http://music.baidu.com/top/new") ele = driver.find_element_by_id("songListWrapper") ul = ele.find_element_by_tag_name("ul") liList = ul.find_elements_by_tag_name("li") for li in liList: up = li.find_elements_by_class_name("up") if up: title = li.find_element_by_class_name("song-title") tltleStr = title.find_element_by_tag_name("a").text authorStr = li.find_element_by_class_name("author_list").text print(title.text,":",authorStr) driver.quit()