淘宝官方有获取商品推广链接的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:
新闻热点
疑难解答