Python automatically downloads audio files using chrome automation

import os
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 设置 Chrome 选项,启用自动下载
chrome_options = webdriver.ChromeOptions()
prefs = {"download.default_directory": os.getcwd()}
chrome_options.add_experimental_option("prefs", prefs)

# 启动 Chrome 浏览器
driver = webdriver.Chrome(options=chrome_options)

# 待获取的网页地址列表
# urls = ['https://ting55.com/book/10-{}'.format(i) for i in range(1, 2)]
urls = ['https://ting55.com/book/10-2']

# 循环遍历每个网页
for i, url in enumerate(urls):
    # 打开网页
    driver.get(url)

    # 等待网页加载完毕
    wait = WebDriverWait(driver, 8)
    # element = wait.until(EC.presence_of_element_located((By.ID, 'audio-player')))
    element = wait.until(EC.presence_of_elemen

Guess you like

Origin blog.csdn.net/gaoxiangfei/article/details/131305312