【问题标题】:python script to upload video ( *.mp4 ) into web portal将视频 ( *.mp4 ) 上传到门户网站的 python 脚本
【发布时间】:2023-01-26 21:17:01
【问题描述】:

我编写了一个 python 脚本,使用 selenium 库将视频文件上传到门户网站。我们的视频文件名每小时都在变化。程序批处理作业创建具有当前日期的视频并写入当前工作目录。程序 b(我的 python 脚本)需要将其上传到网站。

file_input = browser.find_element(By.XPATH, '//*[@id="content"]/input')
abs_path = os.path.abspath("Random.mp4")   #"random" this keep changing every hour
file_input.send_keys(abs_path)

我需要类似的东西

abs_path = os.path.abspath("*.mp4")    #any random filename *.mp4 needs to be uploaded . because it changes everytime. only one video file .mp4 exist at any point of time. 

如果我给出 *.mp4 则 python 脚本失败。

需要更改脚本逻辑的建议。

【问题讨论】:

    标签: python python-3.x video upload selenium-chromedriver


    【解决方案1】:

    自己解决了...

    video_extensions = ['.mp4', '.avi', '.mkv']

    current_directory = os.getcwd()
    
    for root, dirs, files in os.walk(current_directory):
        for file in files:
            if any(file.endswith(ext) for ext in video_extensions):
                file_path = os.path.join(root, file)
                file_input = browser.find_element(By.XPATH, '//*[@id="content"]/input')
                file_input.send_keys(os.path.abspath(file_path))
    

    【讨论】:

      猜你喜欢
      • 2012-10-25
      • 2015-10-07
      • 2016-01-29
      • 1970-01-01
      • 2010-12-31
      • 2012-08-11
      • 2015-07-30
      • 2020-04-09
      • 2019-05-21
      相关资源
      最近更新 更多