python 自动生成淘宝客链接

 
  
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(r'eliteUrl":.*,"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)

 

转载于:https://www.cnblogs.com/xiaojingjing/p/4203785.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值