用简单的几行代码就能调用免费的智能接口,智能聊天、问答,挺实用的
http://www.tuling123.com/openapi/cloud/proexp.jsp
import requests import urllib import urllib2 KEY = ‘d92d20bc1d8bb3cff585bf746603b2a9‘ url = ‘http://www.tuling123.com/openapi/api‘ req_info = u‘讲个笑话‘ query = {‘key‘: KEY, ‘info‘: req_info} headers = {‘Content-type‘: ‘text/html‘, ‘charset‘: ‘utf-8‘} # 方法一、用requests模块以get方式获取内容 r = requests.get(url, params=query, headers=headers) print r.text # 方法二、用urllib和urllib2库获取内容 data = urllib.urlencode(query) req = urllib2.Request(url, data) f = urllib2.urlopen(req) print f.read()
时间: 2024-11-04 12:27:35