运行脚本选订图片存储文件夹,同样的下载过的图片会存在根目录log.txt下,重新运行脚本的话,已经下载过的图片会跳过,低于200kb的图片也会跳过,可以随意调整
[Python] 纯文本查看 复制代码import requests
from bs4 import BeautifulSoup
import os
import urllib.parse
from concurrent.futures import ThreadPoolExecutor, as_completed
from tkinter import Tk, filedialog
def download_image(img_info, log_file_path):
img_url, image_path = img_info
image_name = os.path.basename(image_path)
# 追加写入log.txt
with open(log_file_path, 'a') as log_file:
log_file.write(f'{image_name},')
if os.path.exists(image_path):
print(f'Skipped image: {image_name}')
else:
# 获取文件大小
response = requests.head(img_url)
file_size = int(response.headers.get('Content-Length', 0))
if file_size