【python】7個隨機二次元圖片api接口匯總(附網頁調用示例)


在這里插入圖片描述


1. 韓小韓API

1.1. 接口文檔

https://api.vvhan.com/dongman.html

1.2. 請求地址

https://api.vvhan.com/api/acgimg

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. 接口文檔

http://www.dmoe.cc/

2.2. 請求地址

http://www.dmoe.cc/random.php

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. 接口文檔

http://img.xjh.me/

3.2. 請求地址

  • https

https://img.xjh.me/random_img.php

  • http

http://img.xjh.me/random_img.php

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. 接口文檔

https://www.nck.cc/index.php/archives/3/

4.2. 請求地址

https://www.rrll.cc/tuceng/ecy.php

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. 接口文檔

https://api.ghser.com/acg.html

5.2. 請求地址

https://api.ghser.com/random/api.php

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. 接口文檔

https://acg.yanwz.cn/

6.2. 請求地址

https://acg.yanwz.cn/wallpaper/api.php

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. 接口文檔

https://www.eee.dog/tech/rand-pic-api.html

7.2. 請求地址

https://api.yimian.xyz/img

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只需要替換srcurl屬性值為以下值

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM