python 调用idm下载

官方函数说明:http://www.internetdownloadmanager.com/support/idm_api.html

参考链接:https://pretagteam.com/question/use-idminternet-download-manager-api-with-python

interface ICIDMLinkTransmitter2: ICIDMLinkTransmitter 
{ 
    HRESULT SendLinkToIDM2(BSTR bstrUrl, BSTR bstrReferer, BSTR bstrCookies, BSTR bstrData,
        BSTR bstrUser, BSTR bstrPassword, BSTR bstrLocalPath, BSTR bstrLocalFileName,
        long lFlags, VARIANT reserved1, VARIANT reserved2); 
    /*Transfers one link (URL) to IDM, brings Start Download dialog,
    or just adds the file to IDM download queue if a special flag is set.*/ 

    HRESULT SendLinksArray(BSTR location, VARIANT * pLinksArray); 
    /* Transfers to IDM an array of internet links (URLs). Note that the use of this
    function will bring "Download All Links with IDM" dialog to give user an opportunity
    to review URLs before downloading.*/ 
};

Parameters of SendLinkToIDM2 function: 
bstrUrl - Url to download
bstrReferer - Referer
bstrCookies - cookies
bstrData - PostData (if using POST method)
bstrUser - UserName (if server requires authentication)
bstrPassword - Password
bstrLocalPath - LocalPath (where to save a file on your computer)
bstrLocalFileName - LocalFileName (file name to save with)
lFlags - Flags, can be zero or a combination of the following values:
    1 - do not show any confirmations dialogs;
    2 - add to queue only, do not start downloading.

reserved1 - can be used to set a specific user-agent header with the following way:
    reserved1.vt = VT_BSTR;
    reserved1.bstrVal = pbstrUA;
    if you don’t need to specify a user agent, then reserved1.vt should be set to VT_EMPTY;

reserved2 - not used, you should set reserved2.vt to VT_EMPTY;

Paramerets of SendLinksArray function: 
Location - the referrer of download, it’s assumed that the referrer is a single one
    for the entire array of internet links.
pLinksArray – a pointer to 2 dimensional SAFEARRAY array of BSTR strings.
    For example, for N number of links, the size of the array will be (4 * N).
    For i changing from 0 to N-1 
    a[i,0] elements of the array are URLs to download,
    a[i,1] are cookies for corresponding a[i,0] URLs,
    a[i,2] are link descriptions for corresponding URLs,
    a[0,3] is the user agent, all others elements a[i,3] are not used and should be always NULL.
pip install idm
from idm import IDMan

if __name__ == '__main__':

    downloader = IDMan()
    url = "http://xxxxxxxxxx"
    filename = "1.zip"
    path_to_save = "C:/Users/xxxxx/Downloads/"
    # 你可以把想保存的名字传给 output 这个参数,但是idm发现你的这个名字和服务器传过来的名字不一样的时候他会问你用哪个,使用代码下载大量文件的时候是不太方便的
    # 建议不传这个参数,后期再处理吧
    downloader.download(url, path_to_save, output=None, referrer=None, cookie=None, postData=None, user=None, password=None,confirm=False, lflag=None, clip=False)




文章目录