from selenium.webdriver import ActionChains
ActionChains(driver).move_to_element(背景图片的Xpath).perform()
搞定!!
请看实操视频
奉上完整代码
import openpyxl
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains
'''
铂略网: https://www.bolue.cn/
'''chrome_options = Options()
chrome_driver = "./chromedriver.exe"
driver = webdriver.Chrome()# WebDriverWait(driver, 10, 1).until(EC.presence_of_element_located((By.XPATH,"(//ul)[4]//li//a")))
herf_a = driver.find_elements(By.XPATH,'//ul[@class="clearfix ul course_list"][1]//li')
min_ = driver.find_elements(By.XPATH,'//ul[@class="clearfix ul course_list"]//li//div//span[@class="time"]')
title = driver.find_elements(By.XPATH,'//ul[@class="clearfix ul course_list"][1]//li//a')
img = driver.find_elements(By.XPATH,'//ul[@class="clearfix ul course_list"][1]//li//img')
time.sleep(0.5)print("当页课程数量",len(herf_a))
for i in range(len(herf_a)):start = time.strftime("%Y-%m-%d %H:%M:%S")time.sleep(0.5)ActionChains(driver).move_to_element(img[i]).perform()time.sleep(0.5)time2 = min_[i].textprint(time2)end = time.strftime("%Y-%m-%d %H:%M:%S")print(start, title[i].get_attribute("title"), time2,end)print("----------------------------------------")