Python 调用IDM下载工具下载链接文件Python 调用IDM下载工具下载链接文件Python 调用IDM下载工具下载链接文件Python 调用IDM下载工具下载链接文件
  • 首页
  • 博客
  • 文件
  • 书签
  • 分析
  • 登录
Search
Generic filters

Python 调用IDM下载工具下载链接文件

Published by admin at 2022年3月15日
Categories
  • Python
Tags

IDM是一款优秀的下载器,IDM提供了使用命令行调用的接口

官方说明文档见:https://www.internetdownloadmanager.com/support/command_line.html

6) You may start downloads from command line using command line parameters
You may start IDM from the command line using the following parameters

idman /s
or idman /d URL [/p local_path] [/f local_file_name] [/q] [/h] [/n] [/a]

Parameters:
/d URL - downloads a file, eg.
IDMan.exe /d "http://www.internetdownloadmanager.com/path/File Name.zip"
/s - starts queue in scheduler
/p local_path - defines the local path where to save the file
/f local_file_name - defines the local file name to save the file
/q - IDM will exit after the successful downloading. This parameter works only for the first copy
/h - IDM will hang up your connection after the successful downloading
/n - turns on the silent mode when IDM doesn't ask any questions
/a - add a file, specified with /d, to download queue, but don't start downloading
Parameters /a, /h, /n, /q, /f local_file_name,  /p local_path work only if you specified the file to download with /d URL

这里做一个简单翻译:

使用:
idman /s
或
idman /d URL [/p local_path] [/f local_file_name] [/q] [/h][/n] [/a]
可以进行下载
参数解释:
/d URL #根据URL下载文件
/s #开始下载队列中的任务
/p #定义文件要存储在本地的地址
/f #定义文件存储在本地的文件名
/q #下载成功后IDM将退出。
/h #下载成功后IDM将挂起你的链接
/n #当IDM不出问题时启动静默模式
/a #添加指定文件到/d的下载队列,但是不进行下载

Python 调用IDM下载工具下载链接文件

IDM(Internet DownloadManager) 可以在Windows通过命令行参数启动,以及通过提供参数开始下载。
下面为用 Python 调用IDM下载链接的两种方法。

使用os.system()

import os

def IDMdownload(DownUrl, DownPath, FileName):
    IDMPath = "C:\\Program Files (x86)\\Internet Download Manager\\"
    os.chdir(IDMPath)
    IDM = "IDMan.exe"
    command = ' '.join([IDM, '/d', DownUrl, '/p', DownPath, '/f', FileName, '/a', '/s'])
    os.system(command)

使用subprocess

from subprocess import call
def IDMdown(DownUrl, DownPath, FileName):
    IDMPath = "C:\\Program Files (x86)\\Internet Download Manager\\"  # IDMPath 为IDM安装路径
    os.chdir(IDMPath)
    IDM = "IDMan.exe"
    call([IDM, '/d', DownUrl, '/p', DownPath, '/f', FileName, '/a'])
    call([IDM, '/s'])

Python 调用IDM下载器

使用python调用IDM
(1)os.system()
(2)subprocess
在这里放两个实例

(1)os.system()
def IDMdownload(DownUrl, DownPath, FileName):
    IDM = r"D:\IDM\Internet Download Manager\IDMan.exe"
    os.chdir(IDMPath)
    IDM = "IDMan.exe"
    command = ' '.join([IDM, '/d', DownUrl, '/p', DownPath, '/f', FileName, '/q'])
    print(command)
    os.system(command)

(2)subprocess
# 用于调用CMD命令行
from subprocess import call
# 启动idm下载
IDM = r"D:\IDM\Internet Download Manager\IDMan.exe"
# 下载路径
DownPath = 'D:/下载/'
# 下载文件名称
local_file_name = 'xx'
# 下载文件链接(注意是这个列表)
urlList = ['xxx']
# 将下载链接全部加入到下载列表,之后再进行下载。
for ul in urlList:
    call([IDM, '/d', ul, '/p', DownPath, '/f', local_file_name, '/n', '/a'])
call([IDM, '/s'])
例:
from subprocess import call
IDM = 'C:\Program Files (x86)\Internet Download Manager\IDMan.exe'
down_url = 'https://kbdevstorage1.blob.core.windows.net/asset-blobs/19342_en_1'
output_filename = 'test.jpg'
path = r'C:\Users\你的用户名\Downloads'
call([IDM, '/d', down_url, '/p', path, '/f', output_filename, '/n'])

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Categories

  • 猫
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2022 Alaica Blog support@alaica.com