【python】7个随机二次元图片api接口汇总(附网页调用示例) |
您所在的位置:网站首页 › 电脑com接口图片 › 【python】7个随机二次元图片api接口汇总(附网页调用示例) |
https://api.vvhan.com/dongman.html 1.2. 请求地址https://api.vvhan.com/api/acgimg 1.3. 请求方式get 1.4. 请求参数 字段类型描述returnstr响应数据格式,可选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. 图片预览调用多次发现,该接口返回的图片尺寸大多是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()http://www.dmoe.cc/ 2.2. 请求地址http://www.dmoe.cc/random.php 2.3. 请求方式get 2.4. 请求参数 字段类型描述returnstr响应数据格式,可选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. 图片预览http://img.xjh.me/ 3.2. 请求地址 httpshttps://img.xjh.me/random_img.php httphttp://img.xjh.me/random_img.php 3.3. 请求方式get 3.4. 请求参数 字段类型描述returnstr响应数据格式,可选json或302typestr返回图片类型,可选bg即背景图ctypestr背景图类型,可选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. 图片预览https://www.nck.cc/index.php/archives/3/ 4.2. 请求地址https://www.rrll.cc/tuceng/ecy.php 4.3. 请求方式get 4.4. 请求参数 字段类型描述returnstr响应数据格式,可选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. 图片预览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. 图片预览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. 图片预览https://www.eee.dog/tech/rand-pic-api.html 7.2. 请求地址https://api.yimian.xyz/img 7.3. 请求方式get/post 7.4. 请求参数 字段类型描述typestr图片类型,可选moe为二次元图sizestr图片大小,可选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. 图片预览以樱花API为例 插入图片 背景图片其它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 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |