码农单身是有原因的,从图灵获取api接口,让两个机器人自己聊天,无聊不?
运行环境
任意操作系统,安装python
python+requests
'''
想要学习Python?Python学习交流群:984632579满足你的需求,资料都已经上传群文件,可以自行下载!
'''
from time import sleep
import requests
s = input("请主人输入话题:")
while True:
resp = requests.post("http://www.tuling123.com/openapi/api",data={"key": "4fede3c4384846b9a7d0456a5e1e2943", "info": s, })
resp = resp.json()
sleep(1)
print('小明:', resp['text'])
s = resp['text']
resp = requests.get("http://api.qingyunke.com/api.php", {'key': 'free', 'appid': 0, 'msg': s})
resp.encoding = 'utf8'
resp = resp.json()
sleep(1)
print('小红:', resp['content'])
运行截图