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)