首页 > 编程语言 > 详细

python 自动生成淘宝客链接

时间:2015-01-05 16:14:34      阅读:439      评论:0      收藏:0      [点我收藏+]

class tbk:
    __login_cookie = ""
    __fetch_taobaoke_url = ""
    def __init__(self):
        self.__login_cookie = self.read_file("../cookie.txt") #cookie 文件  
        self.__fetch_taobaoke_url = "http://pub.alimama.com/common/code/getAuctionCode.json?auctionid="
    #获得token        
    def _tb_token_(self):
        token = re.findall("_tb_token_=(.*)(; v=0)",self.__login_cookie)
        return token[0][0]
    def read_file(self,filename):
        all_the_text = ""
        file_object = open(filename)
        try:
            all_the_text = file_object.read( )
        finally:
            file_object.close( )
        return all_the_text

    #获取淘宝客链接
    def getTBKurl(self,**obj):
        url = self.__fetch_taobaoke_url+"%d&adzoneid=%d&siteid=%d&t=&_tb_token_=%s"%(obj[id],obj[adzoneid],obj[siteid],self._tb_token_())
        result = self.fetch(url,self.__login_cookie)
        api = re.findall(reliteUrl":.*,"clickUrl,result)
        if len(api)>0:
            try:
                return api[0].split(\")[2]
            except Exception,ex:
                print Exception,":",ex
                sys.exit()
        else:
            return False

#测试内容,需要加载pycurl和re模块,fetch方法没列出。fetch是pycurl请求方法。 if __name__ == "__main__": my_taobaoke = tbk() print my_taobaoke.getTBKurl(id=40094111949,siteid=4234,adzoneid=123567)

 

python 自动生成淘宝客链接

原文:http://www.cnblogs.com/xiaojingjing/p/4203785.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!