music_tracks = soup.find_all('音乐文本行')
对于music_tracks中的music_track: 打印(音乐曲目) Track_Name = music_track['主要文本'] popularity_bar = music_track.find('音乐流行度酒吧') 流行度 = 流行度_bar['评级'] 如果流行度_bar 否则无 打印(曲目名称)
more_button = music_track.find_all('music-button')[-1]
final_cl = more_button.find('button')
print(final_cl)
final_cl.click()
final_cl = more_button.find('button').click() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError:“NoneType”对象没有属性“click”
我想点击final_cl.click()
试试这个:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Initialize the WebDriver
driver = webdriver.Chrome() # Or whichever browser you're using
# Assuming you have navigated to the desired page using driver.get('your_page_url')
# Find all elements that match the 'music-button' class or any specific identifier your buttons have
music_buttons = driver.find_elements(By.CSS_SELECTOR, 'music-button') # Adjust the selector as needed
# If you're trying to click the last 'music-button' of a specific music track
if music_buttons:
# Find the 'button' element within the last 'music-button'. Adjust the selector if necessary
# This assumes that the structure is consistent and the button you want to click is within the 'music-button' element
final_button = music_buttons[-1].find_element(By.TAG_NAME, 'button')
if final_button:
final_button.click() # This will click the button
else:
print("Button element not found within the music-button.")
else:
print("No music-button elements found.")