Download webp images in batches with IDM and python

Came across a new requirement today. There are many webp pictures on the website. If you open it directly, access is denied, and the browser will open it with 403. It is protected at first glance. It also failed to write python to download in batches. Finally, try it with IDM, and it can be downloaded. But it is too troublesome to download one by one, there are hundreds of them. Then add IDM with python.

Use IDM's command line interface (command line interface, CLI) combined with Python scripts to download images in batches. Follow the steps below:

1. First, please make sure that your computer has installed IDM.

2. Create a text file `urls.txt`, and add image URLs to the file line by line.

3. Create a Python script `idm_downloader.py` and paste the following code into the script:```python


import subprocess
import time

# 更改为 IDM 安装路径下的 IDMan.exe 路径
idm_executable_path = "F:\\TOOLS\\Internet Download Manager\\IDMan.exe"

# 更改为包含图片网址的文本文件路径
url_file_path = "url.txt"

# 读取文本文件并获取图片网址
with open(url_file_path, "r", encoding="utf-8") as url_file:
    image_urls = [url.strip() for url in url_file.readlines()]

# 使用 IDM 下载图片
for image_url in image_urls:
    subprocess.run([idm_executable_path, "/d", image_url, "/n", "/a", "/p", "/q"])
    #time.sleep(2)  # 暂停 2 秒,确保 IDM 添加任务

    # 使用 "/s" 标志启动下载队列
    subprocess.run([idm_executable_path, "/s"])


```

Please note that the variables `idm_executable_path` (the path of IDMan.exe under the IDM installation path) and `url_file_path` (the path of the text file containing the image URL) need to be changed according to the actual situation. Then run the script and IDM will automatically download all the images in the text file.

This code executes IDM on the command line and reads image URLs in a text file line by line. The `/d` flag is used to provide a download link, `/n` means next download task, `/a` means add download to queue, `/p` means use default save path and `/q` means run in quiet mode IDM.

Guess you like

Origin blog.csdn.net/hbqjzx/article/details/131293115