练习题一:
打开百度新歌榜, http://music.baidu.com/top/new
在排名前50的歌曲中,找出其中排名上升的歌曲和演唱者
注意: 有的歌曲名里面有 “影视原声” 这样的标签, 要去掉
最终结果显示的结果如下:
#该方法是用id ,class以及 name定位的写法
from selenium import webdriver
driver=webdriver.Chrome(r'D:\Users\CT-LA\AppData\Local\Programs\Python\Python36\Scripts\chromedriver.exe')
driver.implicitly_wait(0.5) #等待查找元素的事件
driver.get('http://music.taihe.com/top/new')
all_misic=driver.find_element_by_id('songListWrapper')
ul=all_misic.find_element_by_tag_name('ul')
li=ul.find_elements_by_tag_name('li')
for one in li:
up_musics=one.find_elements_by_class_name('up')
if up_musics:
music=one.find_element_by_class_name('song-title ')
up_music=music.find_element_by_tag_name('a').text
name=one.find_element_by_class_name('author_list').text
print(up_music,name)
driver.quit()
以下使用css方法
from selenium import webdriver
driver=webdriver.Chrome(r