1. 韓小韓API
1.1. 接口文檔
1.2. 請求地址
1.3. 請求方式
get
1.4. 請求參數
字段 | 類型 | 描述 |
---|---|---|
return | str | 響應數據格式,可選json |
1.5. 示例代碼
import json, requests
url = 'https://api.vvhan.com/api/acgimg'
params = {'type': 'json'}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
1.6. 響應數據
{
"success": true,
"imgurl": "https://cdn.jsdelivr.net/gh/uxiaohan/GitImgTypecho/Acg/api.vvhan.com[337].jpg",
"info": {
"width": 1920,
"height": 1080,
"type": "img"
}
}
1.7. 圖片預覽
1.8. 溫馨提示
調用多次發現,該接口返回的圖片尺寸大多是1920x1800
,且圖片url
地址中只有最后[ ]
里面的數值在變化,截止目前該變化范圍是0-696
,也就是該接口是從697
張二次元圖片中隨機返回一張。如果你想下載該接口所有的697
張圖片,可以使用下方代碼:
'''依賴模塊 pip install requests '''
import concurrent.futures as cf
import os, time, requests
# 單張圖片下載函數
def down(fname, url):
res = requests.get(url)
with open(fname, 'wb') as f:
f.write(res.content)
# 進度條打印函數
def show(num, _sum, runTime):
barLen = 20
perFin = num/_sum
numFin = round(barLen*perFin)
numNon = barLen-numFin
leftTime = (1-perFin)*(runTime/perFin)
print(
f"{num:0>{len(str(_sum))}}/{_sum}",
f"|{'█'*numFin}{' '*numNon}|",
f"PROCESS: {perFin*100:.0f}%",
f"RUN: {runTime:.0f}S",
f"ETA: {leftTime:.0f}S",
end='\r'
)
if num == _sum:
print()
# 主函數(多線程)
def main():
floder = './img/'
os.makedirs(floder, exist_ok=True)
fmt = 'https://cdn.jsdelivr.net/gh/uxiaohan/GitImgTypecho/Acg/api.vvhan.com[{}].jpg'
total = 697
with cf.ThreadPoolExecutor() as tp:
t1 = time.time()
futures = []
for i in range(total):
url = fmt.format(i)
fname = floder+os.path.basename(url)
future = tp.submit(down, fname, url)
futures.append(future)
count = 0
for future in cf.as_completed(futures):
count += 1
t2 = time.time()
show(count, total, t2-t1)
os.system('pause')
main()
2. 櫻花API
2.1. 接口文檔
2.2. 請求地址
2.3. 請求方式
get
2.4. 請求參數
字段 | 類型 | 描述 |
---|---|---|
return | str | 響應數據格式,可選json |
2.5. 示例代碼
import json, requests
url = 'http://www.dmoe.cc/random.php'
params = {'return': 'json'}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
2.6. 響應數據
{
"code": "200",
"imgurl": "https://tva1.sinaimg.cn/large/0072Vf1pgy1foxkil4o6qj31hc0u0nbz.jpg",
"width": "1920",
"height": "1080"
}
2.7. 圖片預覽
3. 歲月小築API
3.1. 接口文檔
3.2. 請求地址
- https
- http
3.3. 請求方式
get
3.4. 請求參數
字段 | 類型 | 描述 |
---|---|---|
return | str | 響應數據格式,可選json或302 |
type | str | 返回圖片類型,可選bg即背景圖 |
ctype | str | 背景圖類型,可選acg或nature |
3.5. 示例代碼
import json, requests
url = 'https://img.xjh.me/random_img.php'
params = {
'return': 'json',
'type': 'bg',
'cytpe': 'acg'
}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
3.6. 響應數據
{
"error": 0,
"result": 200,
"img": "//img.xjh.me/desktop/bg/acg/53829526_p0.jpg"
}
3.7. 圖片預覽
4. Lucky小站API
4.1. 接口文檔
4.2. 請求地址
4.3. 請求方式
get
4.4. 請求參數
字段 | 類型 | 描述 |
---|---|---|
return | str | 響應數據格式,可選json |
4.5. 示例代碼
url = 'https://www.rrll.cc/tuceng/ecy.php'
params = {
'return': 'json'
}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
4.6. 響應數據
{
"code": "200",
"acgurl": "https://tva4.sinaimg.cn/large/0072Vf1pgy1foxkgc5msdj31hc0u01cv.jpg",
"width": "1920",
"height": "1080",
"size": "jpg"
}
4.7. 圖片預覽
5. 三秋API
5.1. 接口文檔
5.2. 請求地址
5.3. 請求方式
get/post
5.4. 請求參數
空
5.5. 示例代碼
import json, requests
url = 'https://api.ghser.com/random/api.php'
res = requests.get(url)
print(res.url)
5.6. 響應數據
返回302
重定向后的圖片url
https://tva1.sinaimg.cn/large/006gkh44ly1fz1kddbampj31hc0u0tyb.jpg
5.7. 圖片預覽
6. 汐岑API
6.1. 接口文檔
6.2. 請求地址
6.3. 請求方式
get
6.4. 請求參數
空
6.5. 示例代碼
import json, requests
url = 'https://acg.yanwz.cn/wallpaper/api.php'
res = requests.get(url)
with open('test.jpg', 'wb') as f:
f.write(res.content)
6.6. 響應數據
二進制流圖片
6.7. 圖片預覽
7. 囈喵醬API
7.1. 接口文檔
7.2. 請求地址
7.3. 請求方式
get/post
7.4. 請求參數
字段 | 類型 | 描述 |
---|---|---|
type | str | 圖片類型,可選moe為二次元圖 |
size | str | 圖片大小,可選1920x1080 |
7.5. 示例代碼
import json, requests
url = 'https://api.yimian.xyz/img'
params = {
'type': 'moe',
'size': '1920x1080'
}
res = requests.get(url, params=params)
print(res.url)
7.6. 響應數據
返回302
重定向后的圖片url
https://yimian-image.obs.cn-east-2.myhuaweicloud.com/moe/img_865_2048x1152_96.5199966430664_null_normal.jpg?AWSAccessKeyId=6LJRZC0YN3MQXXFOWMIH&Expires=1608815304&Signature=C5BWWC/r1/o230t1VVLHHmH0kF4%3D
7.7. 圖片預覽
8. 調用代碼匯總
# %%1. 韓小韓API
import json, requests
url = 'https://api.vvhan.com/api/acgimg'
params = {'type': 'json'}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
# %%2. 櫻花API
import json, requests
url = 'http://www.dmoe.cc/random.php'
params = {'return': 'json'}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
# %%3. 歲月小築API
import json, requests
url = 'https://img.xjh.me/random_img.php'
params = {
'return': 'json',
'type': 'bg',
'cytpe': 'acg'
}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
# %%4. Lucky小站API
import json, requests
url = 'https://www.rrll.cc/tuceng/ecy.php'
params = {
'return': 'json'
}
res = requests.get(url, params=params).json()
print(json.dumps(res, indent=2))
# %%5. 一葉三秋API
import json, requests
url = 'https://api.ghser.com/random/api.php'
res = requests.get(url)
print(res.url)
# %%6. 汐岑API
import json, requests
url = 'https://acg.yanwz.cn/wallpaper/api.php'
res = requests.get(url)
with open('test.jpg', 'wb') as f:
f.write(res.content)
# %%7. 囈喵醬API
import json, requests
url = 'https://api.yimian.xyz/img'
params = {
'type': 'moe',
'size': '1920x1080'
}
res = requests.get(url, params=params)
print(res.url)
9. 網頁調用示例
以櫻花API
為例
- 插入圖片
<img src="http://www.dmoe.cc/random.php"/>
- 背景圖片
<body style="background: url(http://www.dmoe.cc/random.php);"></body>
其它API
只需要替換src
或url
屬性值為以下值
1. 韓小韓API
https://api.vvhan.com/api/acgimg
2. 櫻花API
http://www.dmoe.cc/random.php
3. 歲月小築API
https://img.xjh.me/random_img.php?return=302
4. Lucky小站API
https://www.rrll.cc/tuceng/ecy.php
5. 一葉三秋API
https://api.ghser.com/random/api.php
6. 汐岑API
https://acg.yanwz.cn/wallpaper/api.php
7. 囈喵醬API
https://api.yimian.xyz/img