python模擬登陸阿里媽媽生成商品推廣鏈接
淘寶官方有獲取商品推廣鏈接的API,但該API屬于增值A(chǔ)PI 普通開發(fā)者沒有調(diào)用權(quán)限 需要申請開通
備注:登陸采用的是阿里媽媽賬號登陸非淘寶賬號登陸
#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數(shù)據(jù)
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爬蟲之模擬登陸csdn的實(shí)例代碼
- python編程使用selenium模擬登陸淘寶實(shí)例代碼
- 利用selenium 3.7和python3添加cookie模擬登陸的實(shí)現(xiàn)
- Python爬蟲利用cookie實(shí)現(xiàn)模擬登陸實(shí)例詳解
- Python模擬登陸淘寶并統(tǒng)計(jì)淘寶消費(fèi)情況的代碼實(shí)例分享
- Python使用Srapy框架爬蟲模擬登陸并抓取知乎內(nèi)容
- 分享一個(gè)常用的Python模擬登陸類
- python3.3教程之模擬百度登陸代碼分享
- python模擬新浪微博登陸功能(新浪微博爬蟲)
- 詳解python項(xiàng)目實(shí)戰(zhàn):模擬登陸CSDN
相關(guān)文章
Python遞歸函數(shù) 二分查找算法實(shí)現(xiàn)解析
這篇文章主要介紹了Python遞歸函數(shù) 二分查找算法實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08使用?PyQt5?設(shè)計(jì)下載遠(yuǎn)程服務(wù)器日志文件程序的思路
這篇文章主要介紹了使用?PyQt5?設(shè)計(jì)下載遠(yuǎn)程服務(wù)器日志文件程序,借助 PyQt5 強(qiáng)大的能力,我們可以通過“拖拉拽”的形式很容易地實(shí)現(xiàn)桌面端程序,只需要將原來的 Python 腳本綁定到 UI 程序的事件中,就實(shí)現(xiàn)了命令行程序到桌面程序的演進(jìn),需要的朋友可以參考下2022-11-11Python 中獲取數(shù)組的子數(shù)組示例詳解
在 Python 中獲取一個(gè)數(shù)組的子數(shù)組時(shí),可以使用切片操作,使用切片操作來獲取一個(gè)數(shù)組的一段連續(xù)的子數(shù)組,并且還可以使用一些方便的語法來簡化代碼,這篇文章主要介紹了如何在 Python 中獲取數(shù)組的子數(shù)組,需要的朋友可以參考下2023-05-05Python3.5面向?qū)ο蟪绦蛟O(shè)計(jì)之類的繼承和多態(tài)詳解
這篇文章主要介紹了Python3.5面向?qū)ο蟪绦蛟O(shè)計(jì)之類的繼承和多態(tài),結(jié)合實(shí)例形式詳細(xì)分析了Python3.5面向?qū)ο蟪绦蛟O(shè)計(jì)中類的繼承與多態(tài)常見用法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2019-04-04python中24小時(shí)制轉(zhuǎn)換為12小時(shí)制的方法
最近需要實(shí)現(xiàn)一個(gè)需求,求用戶輸入24小時(shí)制的時(shí)間,然后顯示12小時(shí)制的時(shí)間。具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06