淘宝官方有获取商品推广链接的API,但该API属于增值API 普通开发者没有调用权限 需要申请开通
备注:登陆采用的是阿里妈妈账号登陆非淘宝账号登陆
复制代码 代码如下:
#coding:utf-8
__author__ = 'liukoo'
import urllib,urllib2,cookielib,re
from hashlib import md5
class alimama:
def __init__(self):
self.header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36'}
#cookie 支持
self.cookie_handle = cookielib.CookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie_handle))
urllib2.install_opener(self.opener)
#登陆
def login(self,username,passwd):
login_data = {
'logname':'',
'originalLogpasswd':'',
'logpasswd':'',
'proxy':'',
'redirect':'',
'style':''
}
login_data['logname'] =username
login_data['originalLogpasswd'] =passwd
login_data['logpasswd'] = md5(login_data['originalLogpasswd']).hexdigest()
source = urllib2.urlopen('http://www.alimama.com/member/minilogin.htm').read()
token_list = re.findall(r"input name='_tb_token_' type='hidden' value='([a-zA-Z0-9]+)'", source)
login_data['_tb_token_'] = token_list[0] if token_list else ''
loginurl = 'https://www.alimama.com/member/minilogin_act.htm'
#拼接post数据
login_data = urllib.urlencode(login_data)
self.header['Referer'] = 'http://www.alimama.com/member/minilogin.htm'
try:
req = urllib2.Request(url=loginurl,data=login_data,headers=self.header)
resp =urllib2.urlopen(req)
html = resp.read()
if str(resp.url).find('success')!=-1:
return True
except Exception,e:
print e
return False
#获取商品的推广链接
def getUrl(self,url):
try:
item_id = re.search(r"id=(\d+)",url)
item_id = item_id.group(1)
html = urllib2.urlopen('http://u.alimama.com/union/spread/common/allCode.htm?specialType=item&auction_id='+item_id).read()
rule = re.compile(r"var clickUrl = \'([^\']+)")
return rule.search(html).group(1)
except Exception,e:
print e
return False
#example
# ali = alimama()
# if ali.login('admin@liuko.com','xxxxxx'):
# url = ali.getUrl('http://item.taobao.com/item.htm?spm=a1z10.1.w4004-1205618817.6.Evkf6O&id=19322457214')
# if url:
# print url
# else:
# print '获取推广链接失败'
# else:
# print '登陆失败'
python模拟登陆,阿里妈妈
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]