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 可能已經失效