Chinaunix首页 | 论坛 | 博客
  • 博客访问: 455931
  • 博文数量: 45
  • 博客积分: 2526
  • 博客等级: 少校
  • 技术积分: 478
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-12 21:04
文章分类

全部博文(45)

文章存档

2014年(1)

2011年(1)

2010年(3)

2009年(22)

2008年(18)

我的朋友

分类: Python/Ruby

2009-06-28 18:11:08

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

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

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

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

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

以上的资料拷贝自

这两天在看TOP, 需要新的赚钱模式.从TOP viki来看,TOP实际上就是开放API, 鼓励大家为淘宝开发
第三发的程序,插件或者应用. 这样对淘宝和第三方程序员都有好处. TOP的盈利模式在下面这个连接
可以找到:


貌似很有钱途, 参考了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('', 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

阅读(4791) | 评论(3) | 转发(0) |
0

上一篇:Perl操作XML文件

下一篇:Run taobao API using GAE

给主人留下些什么吧!~~

crook2009-07-02 21:10:56

恩 有时间看看json

chinaunix网友2009-07-02 17:50:41

这是我在Python 3.0 中的写法

chinaunix网友2009-07-02 17:49:41

写得是不错,不过我更喜欢用json的格式,因为它是原生的列表形式,用不着XML的操作 # -*- coding: utf-8 -*- # vim: set fileencoding=utf-8 import time import hashlib import re from urllib import parse, request #获得当前时间 t = time.localtime() paramArray = { 'app_key':'test', 'method':'taobao.taobaoke.items.get', 'format':'json', '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 ,commiss