简单代码
# 导入函数库
import requests
import os
import time
# 创建目录
goalPath = "D://test"
if not os.path.exists(goalPath):
os.mkdir(goalPath)
# url 变化部分独立
countL = ""
countR = ""
imgFormat = ".jpg"
startIndex = 1
endIndex = 9
for i in range(1, endIndex + 1):
# 延时
time.sleep(0.5)
# 定义网址
url = 'https://xxxxx' + countL + '/' + str(i) + countR + imgFormat
r = requests.get(url)
# 判断文件状态
status = r.status_code
if status != 404:
# 下载头像文件
with open("D://test//"+ str(i) + imgFormat, "wb") as file:
file.write(r.content)
# 输出下载结果
print ('已下载头像图片:' + str(i))
原创文章,作者:dweifng,如若转载,请注明出处:https://blog.ytso.com/272870.html