使用Python中的selenium模块爬取网易云排行榜前100条
from selenium import webdriver
from openpyxl import Workbook
url = 'https://music.163.com/#/discover/toplist'
driver=webdriver.Chrome()
driver.get(url)
driver.switch_to.frame('g_iframe')
tbody=driver.find_element_by_tag_name('tbody')
trs=tbody.find_elements_by_tag_name('tr')
list1=[]
for tr in trs:
list2=[]
list2.append(tr.find_element_by_tag_name('span').text)
list2.append(tr.find_element_by_tag_name('b').get_attribute('title'))
list2.append(tr.find_element_by_class_name('text').get_attribute('title'))
list1.append(list2)