爬虫获取所有图片:

背景:

​ 最近做一些Web题,发现了些网页的背景会随机出现,每一次刷新都会出现不一样的图,感觉有点意思,试着研究下,当然,肯定不是研究咋弄的这个,而是,api里的图怎么爬取:

首先:

​ 接口文档如下:

[LoliApi]: https://docs.loliapi.com/api-shi-yong-wen-dang/sui-ji-er-ci-yuan-tu-pian “LoliApi”

之后直接上源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
import os

def pe():
for i in range(1,3400):
url = "https://img.loliapi.cn/i/pe/img{}.webp".format(str(i))
print(url)
resp = requests.get(url)
if resp.status_code == 404:
break
if os.path.exists("./img/pe/img{}.webp".format(i)):
print("./img/pe/img{}.webp已存在".format(i))
pass
else:
with open("./img/pe/img{}.webp".format(i), 'wb') as f:
f.write(resp.content)

def pc():
for i in range(690,1000):
url = "https://img.loliapi.cn/i/pc/img{}.webp".format(str(i))
print(url)
resp = requests.get(url)
if resp.status_code == 404:
break
if os.path.exists("./img/pc/img{}.webp".format(i)):
print("./img/pc/img{}.webp已存在".format(i))
pass
else:
with open("./img/pc/img{}.webp".format(i),'wb') as f:
f.write(resp.content)


if __name__ == '__main__':
model = int(input())
if model == 1:
pc()
elif model == 0:
pe()

几个不错的api:

樱花二次元图片API-Dmoe

https://www.dmoe.cc/

随机图API

https://image.anosu.top/index.html

LoliApi:

https://docs.loliapi.com/

随机图API——随机返回我老婆(

https://blog.jitsu.top/archives/3/