From 939828b443962fd6af5342bd99b43f94065573f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E8=B4=B5=E7=8F=8D?= <2509165009@student.example.com> Date: Thu, 26 Mar 2026 16:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 26.03.26 09.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 26.03.26 09.py diff --git a/26.03.26 09.py b/26.03.26 09.py new file mode 100644 index 0000000..2f23d2e --- /dev/null +++ b/26.03.26 09.py @@ -0,0 +1,25 @@ +import requests +from bs4 import BeautifulSoup +import time + +url = f'https://picsum.photos/' + +headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'} + +response = requests.get(url,headers=headers,timeout=10) +response.encoding = 'utf-8' +soup = BeautifulSoup(response.text,'html.parser') + +for i in range(5): + print(f"正在下载第{i+1}张图片...") + + try: + img_response = requests.get(url,headers=headers,timeout=10) + with open('image_{i}.jpg','wb') as f: + f.write(img_response.content) + print(f"第{i+1}张图片下载完成!") + except Exception as e: + print(f"第{i+1}张图片下载失败:{e}") + + time.sleep(1) +print("5张图片全部下载完毕!") \ No newline at end of file