import os
import requests
# range_max 注意要比最大页码大1
def download_images(base_url_1,base_url_2,range_max, save_dir):
# 确保目录存在
if not os.path.exists(save_dir):
os.makedirs(save_dir)
for img in range(1,range_max):
# 获取文件完整网络路径
img_url = base_url_1 + str(img) + base_url_2
# 完整的文件保存路径
file_path = os.path.join(save_dir, str(img)+'.jpg')
# 发送 GET请求
response = requests.get(img_url,stream=True)
if response.status_code == 200:
with open(file_path, 'wb') as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
print(str(img)+' download success.')
else:
print('Download failed,status code:', response.status_code)
#六一 https://book.pep.com.cn/1211001601191/files/mobile/1.jpg?230905110633 共142页
url_1 = "https://book.pep.com.cn/1211001601191/files/mobile/"
url_2 = ".jpg?230905110633"
save_file = "Six_Grade_Volume_1"
download_images(url_1, url_2, 143,save_file)