标签:
调用图灵机器人api
#!/usr/bin/env python # coding=utf-8 import urllib import urllib2 api_url=‘http://www.tuling123.com/openapi/api‘ key=‘26b1ef2041bcfac6079ce76e332c5094‘ def get_response(info): headers={‘User-Agent‘:‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)‘ } info1=urllib2.quote(info.encode(‘utf-8‘)) values={‘key‘:key,‘info‘:info1} data=urllib.urlencode(values) print data req=urllib2.Request(api_url,data,headers) response=urllib2.urlopen(req) return response def ex(info): print ‘--->>i:%s‘%info response1=get_response(info) result=response1.read() result=eval(result) result1=result[‘text‘] print ‘--->>rebot:%s‘ % result1 if __name__==‘__main__‘: while 1: try: info=raw_input(‘input some words:‘) ex(info) except KeyboardInterrupt: print‘我走啦‘ break
http://blog.sina.com.cn/s/blog_5dd2af0901012r05.html
http://www.cnblogs.com/linyawen/archive/2012/03/14/2395840.html
http://blog.csdn.net/JGood/article/details/5493824
标签:
原文地址:http://www.cnblogs.com/yeming/p/4765156.html