Python mock landing Ali mother generate merchandise Promotion link _python

Source: Internet
Author: User
Tags md5

Taobao official has access to merchandise promotion links API, but the API belongs to the value-added API ordinary developers do not invoke the right to apply for open

Note: Landing using the Ali Mother account login is not Taobao account login

Copy Code code as follows:

#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 Safa Ri/537.36 '}
#cookie Support
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 ' Get promotion link failed '
# Else:
# print ' Login failed '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.