欢迎来到天天文库
浏览记录
ID:8830549
大小:84.50 KB
页数:3页
时间:2018-04-08
《基于python的影视搜索接口调用代码实例》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、基于Python的影视搜索接口调用代码实例代码描述:基于Python的影视搜索接口调用代码实例代码平台:聚合数据#!/usr/bin/python#-*-coding:utf-8-*-importjson,urllibfromurllibimporturlencode #----------------------------------#影视影讯检索调用示例代码-聚合数据#在线接口文档:http://www.juhe.cn/docs/94#---------------------------------- defmain(): #配置您申请的APPKe
2、y appkey="*********************" #1.影视搜索 request1(appkey,"GET") #2.最近影讯 request2(appkey,"GET") #影视搜索defrequest1(appkey,m="GET"): url="http://op.juhe.cn/onebox/movie/video" params={ "key":appkey,#应用APPKEY(应用详细页查询) "dtype":"",#返回数据的格式,xml或json,默认js
3、on "q":"",#影视搜索名称 } params=urlencode(params) ifm=="GET": f=urllib.urlopen("%s?%s"%(url,params)) else: f=urllib.urlopen(url,params) content=f.read() res=json.loads(content) ifres: error_code=res["error_code"] iferror_code==0:
4、 #成功请求 printres["result"] else: print"%s:%s"%(res["error_code"],res["reason"]) else: print"requestapierror" #最近影讯defrequest2(appkey,m="GET"): url="http://op.juhe.cn/onebox/movie/pmovie" params={ "key":appkey,#应用APPKEY(应用详细页查询
5、) "dtype":"",#返回数据的格式,xml或json,默认json "city":"",#城市名称 } params=urlencode(params) ifm=="GET": f=urllib.urlopen("%s?%s"%(url,params)) else: f=urllib.urlopen(url,params) content=f.read() res=json.loads(content) ifres: error_code=r
6、es["error_code"] iferror_code==0: #成功请求 printres["result"] else: print"%s:%s"%(res["error_code"],res["reason"]) else: print"requestapierror" if__name__=='__main__': main()
此文档下载收益归作者所有