使用Python Selenium抓取dictionary.cambridge.org

使用Python Selenium抓取dictionary.cambridge.org,python,selenium,selenium-webdriver,web-scraping,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Web Scraping,Selenium Chromedriver,我想获得从dictionary.cambridge.org下载mp3文件的链接。xpath已找到正确的按钮,但在任何情况下都无法获取链接。我试图使用.text和.get_attributehref方法。你知道吗 根据从data-src-mp3属性检索链接的url,您需要诱导WebDriverWait,并且可以使用以下代码行: from selenium import webdriver from selenium.webdriver.common.by import By from seleni

我想获得从dictionary.cambridge.org下载mp3文件的链接。xpath已找到正确的按钮,但在任何情况下都无法获取链接。我试图使用.text和.get_attributehref方法。你知道吗

根据从data-src-mp3属性检索链接的url,您需要诱导WebDriverWait,并且可以使用以下代码行:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# lines of code
content = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='circle circle-btn sound audio_play_button uk']")))
print(content.get_attribute("data-src-mp3"))
控制台输出:

https://dictionary.cambridge.org/media/english-polish/uk_pron/u/ukh/ukhun/ukhunch001.mp3

完成。如我所见,使用Selenium.IMO下载该文件是不可能的,可以使用Selphi下载该文件,但是您可以考虑为这个问题增加一个新的票证。
https://dictionary.cambridge.org/media/english-polish/uk_pron/u/ukh/ukhun/ukhunch001.mp3