Skip to content

Commit 2203a2e

Browse files
committed
完成自动登录,不过验证码要手动识别
1 parent 8b863d9 commit 2203a2e

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

TaoBao/TBLogin.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import urllib,urllib2,cookielib
66

77
class TBLogin():
8+
"""
9+
自动登录淘宝
10+
"""
811

912
user = None
1013
pwd = None
@@ -82,12 +85,15 @@ def getLoginData(self):
8285
}
8386
return login_data
8487

85-
def checkLoginSucceed(self):
86-
s = self.request('http://i.taobao.com')
87-
print s
88+
def checkLoginSucceed(self,source):
89+
return source.find('<div class="mt-edit-userinfo">') != -1
8890

8991
def login(self,postData = None):
92+
"""
93+
postData: 需要提交的数据
9094
95+
True 登录成功,否则失败。
96+
"""
9197
if postData is None:
9298
postData = self.getLoginData()
9399

@@ -97,6 +103,7 @@ def login(self,postData = None):
97103
error = self.checkLoginError(source)
98104
if error:
99105
print error
106+
100107
if error.find('为了您的账号安全,请输入验证码。') != -1 \
101108
or error.find('验证码错误,请重新输入。') != -1:
102109
r = self.__verifyCode.search(source)
@@ -108,16 +115,22 @@ def login(self,postData = None):
108115
os.system('verifyCode.jpg')
109116
postData['need_check_code'] = 'true'
110117
postData['TPL_checkcode'] = raw_input("please input verifycode:")
111-
self.login(postData)
118+
return self.login(postData)
112119

113-
if error.find('您输入的密码和账户名不匹配,请重新输入') != -1:
120+
elif error.find('您输入的密码和账户名不匹配,请重新输入') != -1:
114121
print '您输入的密码和账户名不匹配,请重新输入'
115-
return
122+
return False
123+
124+
else:
125+
return False
126+
116127
else:
117-
# self.checkLoginSucceed()
118-
print self.request('http://taojinbi.taobao.com/record/coin_get.htm?spm=a1z01.1000834.0.78.9510b9&tracelog=qzindex005')
119-
120-
128+
if self.checkLoginSucceed(source):
129+
return True
130+
else:
131+
print '登录没有错误,但是登录不成功'
132+
return False
133+
121134
def checkLoginError(self,source):
122135
r = self.__commonError.search(source)
123136
return r.group(1) if r else None
@@ -143,8 +156,3 @@ def request(self,url,postData=dict()):
143156
print info[0],":",info[1]
144157
return None
145158

146-
if __name__ == '__main__':
147-
t = TBLogin()
148-
t.user = '[email protected]'
149-
t.pwd = 'autorun123456'
150-
t.login()

0 commit comments

Comments
 (0)