img_crawler/crawler.py
2020-12-02 22:31:54 +08:00

25 lines
754 B
Python

import os
import requests
import time
def getImg():
# 获取当前绝对地址
path = os.path.abspath('.')
# 拼接新地址
path = os.path.join(path,'img')
# 创建文件夹
os.mkdir(path)
folder_url = path
for index in range(1,1001):
print('当前index%s'%(index))
# url = 'https://i.picsum.photos/id/'+ str(index) +'/1920/1080.jpg'
url = 'https://img.infinitynewtab.com/wallpaper/' + str(index) + '.jpg'
img_url = os.path.join(folder_url,str(index%1000)+'.jpg')
img = requests.get(url).content
with open(img_url, 'wb') as f:
f.write(img)
time.sleep(1)
print("正在下载第{}张图片".format(index))
index += 1
getImg()