我试图从 url: audio file 使用 selenium、python 和 Chrome 浏览器下载音频文件。(注意:请使用耳机,因为音频会自动播放并使用 chrome 浏览器打开文件)。
但是当我在显示下载选项的三个点上使用 Inspect 元素时,我找不到在代码中引用该元素的任何方法。那么,有没有其他方法可以按下“三个点”按钮,然后按下“下载按钮”?
下面是我为执行该操作而编写的代码。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
s=Service(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
preferences = {'download.default_directory': 'some_path'}
options.add_experimental_option('prefs', preferences)
driver = webdriver.Chrome(service=s, options=options)
driver.maximize_window()
driver.get('https://www.valmiki.iitk.ac.in/sites/default/files/audio/1-1-1.mp3')
action = ActionChains(driver)
dot_dot_dot = driver.find_element(By.XPATH, "//video[@name='media']")
dot_dot_dot.click().perform()
# remaining code to click on the download button