Skip to content

Commit 605b041

Browse files
committed
初始化淘宝自动操作模块
1.开始编写自动登陆淘宝
1 parent b73aed9 commit 605b041

File tree

6 files changed

+123
-5
lines changed

6 files changed

+123
-5
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
.settings/
3+
.project
4+
.pydevproject
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
eclipse.preferences.version=1
22
encoding//Notification/mail.py=gbk
3+
encoding//TaoBao/TBLogin.py=gbk
4+
encoding/login.py=gbk

Notification/__init__.py

Whitespace-only changes.

Notification/mail.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class Mail():
1515
mail_pass = "autorun"
1616
mail_postfix = "163.com"
1717

18-
def SendMail(self, toList, title, content,fromAddress=None):
18+
def SendMail(self, toList, title, content, fromAddress=None):
1919
'''
2020
toList:发给谁
2121
fromAddtress:来自于
2222
title:主题
2323
content:内容
24-
send_mail("aaa@126.com","sub","content")
24+
Mail().SendMail(["qianlf2008@163.com,[email protected]"], "title", "content"):
2525
'''
2626
me = "AutorunForScott<[email protected]>"
2727
if fromAddress is None:
@@ -42,10 +42,8 @@ def SendMail(self, toList, title, content,fromAddress=None):
4242
print str(e)
4343
return False
4444

45-
46-
4745
if __name__ == "__main__":
48-
if Mail().SendMail("[email protected]", "title", "content"):
46+
if Mail().SendMail(["[email protected],[email protected]"], "title", "content"):
4947
print "发送成功"
5048
else:
5149
print "发送失败"

TaoBao/TBLogin.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#coding=gbk
2+
3+
from __future__ import unicode_literals
4+
import sys,re
5+
import urllib,urllib2,cookielib
6+
7+
class TBLogin():
8+
9+
def __init__(self,user,pwd):
10+
#获取一个保存cookie的对象
11+
cj = cookielib.LWPCookieJar()
12+
#将一个保存cookie对象,和一个HTTP的cookie的处理器绑定
13+
cookie_support = urllib2.HTTPCookieProcessor(cj)
14+
#创建一个opener,将保存了cookie的http处理器,还有设置一个handler用于处理http的URL的打开
15+
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
16+
#将包含了cookie、http处理器、http的handler的资源和urllib2对象板顶在一起
17+
urllib2.install_opener(opener)
18+
19+
self.user,self.pwd = user,pwd
20+
21+
def getHeaders(self):
22+
headers = {
23+
"User-Agent":"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",
24+
#"User-Agent" = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13",
25+
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
26+
"Accept-Language":"zh-cn,zh;q=0.5",
27+
#"Accept-Encoding":"gzip,deflate",
28+
"Accept-Charset":"GB2312,utf-8;q=0.7,*;q=0.7",
29+
"Keep-Alive":"115",
30+
"Connection":"keep-alive"
31+
}
32+
return headers
33+
34+
def getLoginData(self):
35+
"""
36+
得到登陆淘宝时所需提交的数据
37+
"""
38+
39+
login_data = {
40+
'ua':'',
41+
'TPL_username':self.user.encode('gbk'),
42+
'TPL_password':self.pwd,
43+
'TPL_checkcode':'',
44+
'need_check_code':'',
45+
'longLogin':'1', #十天免登陆
46+
'action':'Authenticator',
47+
'event_submit_do_login':'anything',
48+
'TPL_redirect_url':'',
49+
'from':'tb',
50+
'fc':'default',
51+
'style':'default',
52+
'css_style':'',
53+
'tid':'',
54+
'support':'000001',
55+
'CtrlVersion':'1,0,0,7',
56+
'loginType':'3',
57+
'minititle':'',
58+
'minipara':'',
59+
'umto':'',
60+
'pstrong':'3',
61+
# 'longLogin':'-1',
62+
'llnick':'',
63+
'sign':'',
64+
'need_sign':'',
65+
'isIgnore':'',
66+
'full_redirect':'',
67+
'popid':'',
68+
'callback':'',
69+
'guf':'',
70+
'not_duplite_str':'',
71+
'need_user_id':'',
72+
'poy':'',
73+
'gvfdcname':'',
74+
'gvfdcre':'',
75+
'from_encoding':''
76+
}
77+
return login_data
78+
79+
def login(self):
80+
81+
url = 'https://login.taobao.com/member/login.jhtml'
82+
source = self.request(url,self.getLoginData())
83+
if source:
84+
print source
85+
print self.checkLoginError(source)
86+
87+
def checkLoginError(self,source):
88+
89+
needVerifyCodeError = re.compile('<div id="J_Message" class="login-msg msg">.*<p class="error">(.*?)</div>',re.S)
90+
r = needVerifyCodeError.search(source)
91+
return r.group(1) if r else None
92+
93+
def request(self,url,postData=dict()):
94+
95+
postData = urllib.urlencode(postData) if postData else None
96+
header = self.getHeaders()
97+
98+
req = urllib2.Request(
99+
url = url,
100+
data = postData,
101+
headers = header
102+
)
103+
try:
104+
request = urllib2.urlopen(req)
105+
source = request.read()
106+
# print request.code,request.msg
107+
request.close()
108+
return source
109+
except:
110+
info=sys.exc_info()
111+
print info[0],":",info[1]
112+
return None
113+
114+
if __name__ == '__main__':

TaoBao/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)