上传文件至 /

This commit is contained in:
2026-03-26 16:06:36 +08:00
parent 32e380d0b6
commit 939828b443

25
26.03.26 09.py Normal file
View File

@@ -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张图片全部下载完毕!")