1 ''' Python3'''
2 import requests #导入requests库 3 import json #导入json库 4 key = '3119f1e3610f42c5977ea73c4097cb1c' # 单引号里写你注册的的图灵机器人apikey 5 while True: #主循环 6 info = input('\n我:') #输入对话信息 7 url = 'http://www.tuling123.com/openapi/api?key='+key+'&info='+info # 拼接 url 8 res = requests.get(url) # 得到数据 9 res.encoding = 'utf-8' # 防止中文乱码 10 data = json.loads(res.text) # 将得到的 json 格式的信息转换为 Python 的字典格式 11 print('\nBot: '+data['text']) # 输出结果
第四行的 apikey 可能已经失效