From 7bb5b00ee6f036f9f143d0c3f6d9cde6ad291402 Mon Sep 17 00:00:00 2001 From: 2509165045 <2509165045@student.edu.cn> Date: Thu, 26 Mar 2026 15:59:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A5=20?= =?UTF-8?q?=E7=88=AC=E5=8F=96=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test(3).py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test(3).py diff --git a/test(3).py b/test(3).py new file mode 100644 index 0000000..39aeb6f --- /dev/null +++ b/test(3).py @@ -0,0 +1,27 @@ + +import requests +from bs4 import BeautifulSoup + +headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'} + +for i in range(1, 6): + # 使用不同的图片ID来获取不同的图片 + # 方式1:使用随机图片(推荐) + url = f'https://picsum.photos/800/600?random={i}' + + # 方式2:使用固定尺寸的特定ID图片(备选) + # url = f'https://picsum.photos/id/{i + 10}/800/600' + + print(f"正在下载第 {i} 张图片...") + + response = requests.get(url, headers=headers, timeout=10) + response.encoding = 'utf-8' + + with open(f'image_{i}.jpg', 'wb') as f: + f.write(response.content) + + print(f"第 {i} 张图片下载完成,保存为 image_{i}.jpg") + +print("所有图片下载完成!") + +