from selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECbrowser = webdriver.Chrome()browser.get('https://music.163.com/#')ranke = browser.find_element_by_xpath('//*[@id="g_nav2"]/div/ul/li[2]/a/em') # 查到排行榜按钮ranke.click() # 点击frame = browser.find_element_by_id('g_iframe') # 查询framebrowser.switch_to.frame(frame) # 切换frameranke_table = browser.find_element_by_tag_name('tbody') # 查询表trs = ranke_table.find_elements_by_tag_name('tr') # 查询行for tr in trs: # 遍历行 name = tr.find_element_by_tag_name('b') # 查到title print(name.get_attribute('title')) # 输出titlebrowser.switch_to.parent_frame() # 切换到frame上级browser.find_element_by_xpath('//*[@id="g_nav2"]/div/ul/li[1]/a/em').click() # 查到推荐按钮并点击