-
Notifications
You must be signed in to change notification settings - Fork 0
/
nike.py
executable file
·169 lines (159 loc) · 6.08 KB
/
nike.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#coding=utf-8
import StringIO
import gzip
import pprint
import urllib
import urllib2
import cookielib
import time
from selectsize import select_size, INFO, HEADERS
import json
# url = "http://www.nikestore.com.cn/product/310805-106/detail.htm"
# size = select_size(url, [u"42",u"42.5",u"43",u"44",u"44.5",u"45"])[0]
# print size
def login():
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
# reqlogin = urllib2.Request("http://www.nikestore.com.cn/member/login.htm")
# urllib2.urlopen(reqlogin)
print cj
req = urllib2.Request("http://www.nikestore.com.cn/servlet/securityImage?0.507514755474403767")
for key in HEADERS:
req.add_header(key, HEADERS[key])
resp = urllib2.urlopen(req, timeout=10)
print cj
img = resp.read()
with open("1.jpeg", "wb") as f:
f.write(img)
b = raw_input(">>>")
data = {"loginName": "xsuperj2012",
"password": "xj198898",
"passwordAgain": b,
"rememberLoginName": "checked"}
data = urllib.urlencode(data)
req = urllib2.Request("http://www.nikestore.com.cn/member/login.json?loxiaflag=1392346369990",
data=data)
for key in HEADERS:
req.add_header(key, HEADERS[key])
resp = urllib2.urlopen(req)
if json.loads(resp.read()).get("loginRedirectPath") == "/":
print "登录成功"
for i in cj:
print (i.name + '=' + i.value + ';')
return True
else:
print json.loads(resp.read())
return False
def addShoppingCart():
profile = urllib2.Request("http://www.nikestore.com.cn/shoppingcart/add",
data=urllib.urlencode({"upc": size, "count": "1"})
)
for key in HEADERS:
profile.add_header(key, HEADERS[key])
profile.add_header("Referer", "%s#" % url)
profile.add_header("Content-Length", "%s" % len(str(urllib.urlencode({"upc": size, "count": "1"}))))
profileresp = urllib2.urlopen(profile)
try:
json_obj = json.loads(profileresp.read())
print json_obj
# if json_obj.get("commonTransactionBackWarnEntity")["isSuccess"]:
# return True
# else:
# print json_obj.get("commonTransactionBackWarnEntity")["description"]
# return False
except Exception, e:
print e
def check():
profile = urllib2.Request("http://www.nikestore.com.cn/transaction/checkValidateCode.json",
data=urllib.urlencode({})
)
for key in HEADERS:
profile.add_header(key, HEADERS[key])
profile.add_header("Referer", "http://www.nikestore.com.cn/transaction/check")
profile.add_header("Content-Length","0")
profileresp = urllib2.urlopen(profile)
try:
json_obj = json.loads(profileresp.read())
print json_obj
# if json_obj.get("commonTransactionBackWarnEntity")["isSuccess"]:
# return True
# else:
# print json_obj.get("commonTransactionBackWarnEntity")["description"]
# return False
except Exception, e:
print e
def doValidator():
profile = urllib2.Request("http://www.nikestore.com.cn/transaction/doValidatorQsGoToTransactionCheck2",
data=urllib.urlencode({"upc": size, "count": "1"})
)
for key in HEADERS:
profile.add_header(key, HEADERS[key])
profile.add_header("Referer", "%s###" % url)
profile.add_header("Content-Length", "%s" % len(str(urllib.urlencode({"upc": "00823229699172", "count": "1"}))))
profileresp = urllib2.urlopen(profile)
try:
json_obj = json.loads(profileresp.read())
print json_obj
if json_obj.get("commonTransactionBackWarnEntity")["isSuccess"]:
return True
else:
print json_obj.get("commonTransactionBackWarnEntity")["description"]
return False
except Exception, e:
print e
def normalReq():
qs_req = urllib2.Request("http://www.nikestore.com.cn/transaction/create?loxiaflag=%d" % int(time.time() * 1000),
data=urllib.urlencode(INFO))
for key in HEADERS:
qs_req.add_header(key, HEADERS[key])
qs_req.add_header("Referer", "http://www.nikestore.com.cn/transaction/check")
qs_req.add_header("Content-Length", "%s" % len(str(urllib.urlencode(INFO))))
qs_resp = urllib2.urlopen(qs_req)
json_obj = json.loads(qs_resp.read())
isSuccess = json_obj.get("transactionCreateBackWarnEntity")["isSuccess"]
msg = json_obj.get("transactionCreateBackWarnEntity")["description"]
print json_obj
print msg
return isSuccess, msg
def qsReq():
qs_req = urllib2.Request("http://www.nikestore.com.cn/transaction/create/qs?loxiaflag=%d" % int(time.time() * 1000),
data=urllib.urlencode(INFO))
for key in HEADERS:
qs_req.add_header(key, HEADERS[key])
qs_req.add_header("Referer", "http://www.nikestore.com.cn/transaction/check/qs")
qs_req.add_header("Content-Length", "%s" % len(str(urllib.urlencode(INFO))))
qs_resp = urllib2.urlopen(qs_req)
json_obj = json.loads(qs_resp.read())
isSuccess = json_obj.get("transactionCreateBackWarnEntity")["isSuccess"]
msg = json_obj.get("transactionCreateBackWarnEntity")["description"]
print json_obj
print msg
return isSuccess, msg
def limit():
isValid = False
while True:
if isValid:
issuccess, msg = qsReq()
if not issuccess:
print msg
time.sleep(1)
else:
print "完成"
break
else:
if doValidator():
isValid = True
else:
time.sleep(1)
if __name__ == "__main__":
size = "00091205064379"
size = "00091205073135"
login()
url = raw_input("url:")
size = raw_input("size:")
limit()
# login()
# addShoppingCart()
# check()
# normalReq()