文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Try taobao open API in python

Try taobao open API in python

时间:2009-06-28  来源:crook

淘宝开放平台,是指由淘宝网提供的,面向第三方的开放式电子商务服务基础服务框架。
其主要内容包括:以OpenAPI形式开放的淘宝网电子商务基础服务、淘宝网自有的开放式应用平
台、对第三方应用平台的开放式基础支持。英文全称是“Taobao Open Platform”, 简写为“TOP”.

淘宝开放平台的宗旨是高效、安全、稳定的提供淘宝网电子商务基础服务;
目标是建立以淘宝开放平台为基础的大淘宝商业生态系统。

宝开放平台(TOP)在设计之初就考虑到如何能够为TOP开发者带来实际的收入,帮助各种类型
的TOP开发者成长和壮大。

TOP的盈利模式清晰,实际操作性强。TOP鼓励开发者选择自身具有优势的业务方向,
融合如下的一种或多种盈利模式,设计出基于TOP的产品。TOP的盈利模式可以部分支持多
个业务参与方的利益分配,为盈利模式的深化和发展打下基础。

......
......

以上的资料拷贝自 http://open.taobao.com/

这两天在看TOP, 需要新的赚钱模式.从TOP viki来看,TOP实际上就是开放API, 鼓励大家为淘宝开发
第三发的程序,插件或者应用. 这样对淘宝和第三方程序员都有好处. TOP的盈利模式在下面这个连接
可以找到:
http://wiki.open.taobao.com/index.php/%E7%9B%88%E5%88%A9%E6%A8%A1%E5%BC%8F

貌似很有钱途, 参考了viki上的实例代码, 于是有了下面的小代码短,算是taobao API的入门程序了.
因为TOP API是基于REST的,与具体语言无关.我这里用的python, 先包装API的参数,然后调用
urlopen打开url. 拿到结果之后,用minidom做了简单的处理,让用户可读.

源代码和运行结果如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import urllib
import urllib2
import time
import md5
from xml.dom import minidom
 
t = time.localtime()

paramArray = {
    'app_key':'test',
    'method':'taobao.taobaoke.items.get',
    'format':'xml',
    'v':'1.0',
    'timestamp':time.strftime('%Y-%m-%d %X', t),
    'fields':'iid,title,nick,pic_url,price,click_url,commission,\
              commission_rate,commission_num ,commission_volume ',
    'pid':'mm_5410_0_0',
    'cid':'1512',
    'page_no':'1',
    'page_size':'6'
}

def _sign(param,sercetCode):
    src = sercetCode + ''.join(["%s%s" % (k, v) for k, v in sorted(param.items())])
    return md5.new(src).hexdigest().upper()
 
# generate sign
sign = _sign(paramArray, 'test');
paramArray['sign'] = sign

form_data = urllib.urlencode(paramArray)
#print form_data

urlopen = urllib2.urlopen('http://gw.sandbox.taobao.com/router/rest', form_data)
 
rsp = urlopen.read();
xmldoc = minidom.parseString(rsp)

rsp = rsp.decode('UTF-8');
print rsp

# parse output
print "--------------------------------------------------------------------------------"
taobaokeItem = xmldoc.getElementsByTagName('taobaokeItem')
for i in range(0, taobaokeItem.length):
    #print taobaokeItem[i].toxml()
    print "###########################################"

    attr = taobaokeItem[i].attributes
    for (key, value) in attr.items():
        print key, "=>", value

    nodes = taobaokeItem[i].childNodes
    for j in range(0, nodes.length):
        name = nodes[j].nodeName
        value = nodes[j].childNodes[0].nodeValue
        print name, "=>", value

ray@localhost taobao]$ python test.py
<?xml version="1.0" encoding="utf-8" ?><rsp><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:1]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:1]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:2]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:2]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:3]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:3]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:4]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:4]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:5]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:5]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem><taobaokeItem><iid><![CDATA[72b31835f55b6b6c35beab8c753989c1]]></iid><title><![CDATA[淘宝客测试数据商品名称:6]]></title><pic_url><![CDATA[http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg]]></pic_url><price><![CDATA[100]]></price><click_url><![CDATA[http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625]]></click_url><nick><![CDATA[淘宝客测试数据卖家昵称:6]]></nick><commission><![CDATA[22.05]]></commission><commission_rate><![CDATA[350.00]]></commission_rate><commission_num><![CDATA[10]]></commission_num><commission_volume><![CDATA[54]]></commission_volume></taobaokeItem></rsp><!--xvm176.sqa-->
--------------------------------------------------------------------------------
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:1
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:1
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:2
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:2
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:3
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:3
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:4
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:4
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:5
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:5
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54
###########################################
iid => 72b31835f55b6b6c35beab8c753989c1
title => 淘宝客测试数据商品名称:6
pic_url => http://img.taobao.com/bao/uploaded/i2/T1SxBeXg5XMdMUfdMZ_031728.jpg
price => 100
click_url => http://s.click.alimama.com/ma_a?e=7TbRJUSX6oob60193a32e1ad625
nick => 淘宝客测试数据卖家昵称:6
commission => 22.05
commission_rate => 350.00
commission_num => 10
commission_volume => 54

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载