#!/usr/bin/python |
# -*- coding: utf-8 -*- |
import json, urllib |
from urllib import urlencode |
|
#---------------------------------- |
# 域名备案查询调用示例代码 - 聚合数据 |
# 在线接口文档:http://www.juhe.cn/docs/68 |
#---------------------------------- |
|
def main(): |
|
#配置您申请的APPKey |
appkey = "*********************" |
|
#1.备案查询 |
request1(appkey, "GET" ) |
|
|
|
#备案查询 |
def request1(appkey, m = "GET" ): |
url = "http://api.juheapi.com/japi/beian" |
params = { |
"key" : appkey, #应用APPKEY(应用详细页查询) |
"type" : "", #0通过网站名称查询,如:聚合数据平台 <br/>1通过域名查询,如:juhe.cn<br/>2通过网站首页查询,如www.juhe.cn<br/>3通过许可证号查询查询,如:苏ICP备14006450号-3<br/>5通过主办单位名称查询,如:苏州新科兰德科技有限公司 |
"keyword" : "", #对应type的值,如:juhe.cn |
"v" : "", #版本号,固定1.0 |
|
} |
params = urlencode(params) |
if m = = "GET" : |
f = urllib.urlopen( "%s?%s" % (url, params)) |
else : |
f = urllib.urlopen(url, params) |
|
content = f.read() |
res = json.loads(content) |
if res: |
error_code = res[ "error_code" ] |
if error_code = = 0 : |
#成功请求 |
print res[ "result" ] |
else : |
print "%s:%s" % (res[ "error_code" ],res[ "reason" ]) |
else : |
print "request api error" |
|
|
|
if __name__ = = '__main__' : |
main() |