::-- ZoomQuiet [2008-03-04 08:25:49]
Contents
1. 招商银行请愿机器人
Toggle line numbers
1 #!/usr/bin/python
2
3 import httplib
4 httplib.HTTPConnection.debuglevel = 1
5 httplib.HTTPSConnection.debuglevel = 1
6
7 import urllib
8 import urllib2
9 import sys
10 from time import *
11
12 class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
13 def http_error_301(self, req, fp, code, msg, headers):
14 result = urllib2.HTTPRedirectHandler.http_error_301(
15 self, req, fp, code, msg, headers)
16 result.status = code
17 return result
18
19 def http_error_302(self, req, fp, code, msg, headers):
20 result = urllib2.HTTPRedirectHandler.http_error_302(
21 self, req, fp, code, msg, headers)
22 result.status = code
23 return result
24
25 if len(sys.argv)>=2:
26 debug = sys.argv[1]
27 else:
28 debug = ''
29
30 #print 'Start protest...'
31
32 YOUR_CARD_NUMBER = '6225880151465146'
33 YOUR_NAME = '\xC0\xEE\xC0\xEE'
34 YOUR_WORDS = '\xD7\xF7\xCE\xAA\xD5\xD0\xC9\xCC\xD2\xF8\xD0\xD0\xB5\xC4\xD6\xD2\xCA\xB5\xD3\xC3\xBB\xA7\xA3\xAC\xCE\xD2\xD5\xE6\xB3\xCF\xB5\xD8\xCF\xA3\xCD\xFB\xD5\xD0\xC9\xCC\xD2\xF8\xD0\xD0\xC4\xDC\xB9\xBB\xB9\xD8\xD5\xD5\xD4\xBD\xC0\xB4\xD4\xBD\xB6\xE0\xB5\xC4\xB7\xC7\xCE\xA2\xC8\xEDWindows\x2FIE\xCF\xB5\xCD\xB3\xD3\xC3\xBB\xA7\xA3\xAC\xBE\xA1\xBF\xEC\xBF\xAA\xB7\xA2\xB3\xF6\xD6\xA7\xB3\xD6FireFox\xBA\xCD\x2F\xBB\xF2Linux\x2FMac+OS+X\x2FUNIX\xCF\xB5\xCD\xB3\xB5\xC4\xD5\xD0\xC9\xCC\xD2\xF8\xD0\xD0\xB4\xF3\xD6\xDA\xB0\xE6\xBA\xCD\xBB\xF2\xD7\xA8\xD2\xB5\xB0\xE6\xA1\xA3\x0D\x0A\xD4\xDA\xB4\xCB\xCF\xD7\xC9\xCF\xCE\xD2\xD7\xEE\xB3\xCF\xD6\xBF\xB5\xC4\xD0\xBB\xD2\xE2\xA3\xA1'
35
36 c_First = 'https://pbsz.ebank.cmbchina.com/CmbBank_GenShell/UI/GenShellPC/Login/Login.aspx?logintype=C'
37 c_UA = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322)'
38
39 protestDict = {'__VIEWSTATE':'',\
40 'ddlServiceType':'D',\
41 'txtEmail':'',\
42 'txtPhone0':'',\
43 'txtPhone':'',\
44 'rblSugType':'A',\
45 'ddlIDType':'0',\
46 'txtCardNo':YOUR_CARD_NUMBER,\
47 'txtName':YOUR_NAME,\
48 'ddlBsnType':'E',\
49 'txtQuestion':YOUR_WORDS,\
50 #'btnSend':'\xB7\xA2+\xCB\xCD',\
51 'hdOld':'',\
52 'hdHelper':'close',\
53 'hdIDType':'8',\
54 'hdID':'',\
55 'hdSwitch':'0',\
56 'imageFile':''}
57
58 #
59 # First
60 #
61 cookie = ''
62 req = urllib2.Request(url=c_First)
63 req.add_header('User-Agent', c_UA)
64 req.add_header('Connection','Keep-Alive')
65 req.add_header('Accept-Language','en-us')
66 req.add_header('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*');
67 req.add_header('UA-CPU', 'x86')
68 req.add_header('Accept-Encoding', 'gzip, deflate')
69 first = urllib2.urlopen(req)
70 #print first.info()
71 #print first.headers.dict
72 r_First = first.read()
73 r_First = r_First[r_First.index('https://forum.cmbchina.com'):]
74 r_First = r_First[0:r_First.index(' ')-1]
75 #print
76 #print r_First
77
78 u_Second = r_First
79 u_Second = u_Second.replace('&', '&')
80 req = urllib2.Request(url=u_Second)
81 req.add_header('User-Agent', c_UA)
82 req.add_header('Connection','Keep-Alive')
83 req.add_header('Accept-Language','en-us')
84 req.add_header('Accept', '*/*');
85 req.add_header('UA-CPU', 'x86')
86 req.add_header('Accept-Encoding', 'gzip, deflate')
87 second = urllib2.urlopen(req)
88 if 'set-cookie' in second.headers.dict:
89 cookie = second.headers.dict['set-cookie']
90 else:
91 cookie = ''
92 #print second.info()
93 #print second.headers.dict
94 r_Second = second.read()
95 #print
96 #print r_Second
97
98 sleep(1)
99
100 okexit = 1
101 while (okexit) :
102 r_Second = r_Second[r_Second.index('action=\"Service.'):]
103 u_Third = r_Second[len('action=\"'):r_Second.index(' ')-1]
104 ppos = r_Second.index('name=\"__VIEWSTATE\" value=\"')
105 r_Second = r_Second[ppos+len('name=\"__VIEWSTATE\" value=\"'):]
106 p_Third = r_Second[0:r_Second.index(' ')-1]
107
108 u_Third = u_Third.replace('&', '&')
109 #print u_Third
110 #print p_Third
111
112 #print strftime("%H : %M : %S", gmtime())
113 sleep(1)
114 #print strftime("%H : %M : %S", gmtime())
115
116 refer = u_Second
117 req = urllib2.Request(url=u_Second)
118 req.add_data(urllib.urlencode({'__VIEWSTATE': p_Third, 'hdContinute': '1',\
119 'btnGo': 'go'}))
120 req.add_header('User-Agent', c_UA)
121 req.add_header('Connection','Keep-Alive')
122 req.add_header('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*');
123 req.add_header('UA-CPU', 'x86')
124 req.add_header('Accept-Encoding', 'gzip, deflate')
125 if len(cookie)>0:
126 req.add_header('Cookie', cookie[0:cookie.find(';')])
127
128 opener = urllib2.build_opener(SmartRedirectHandler())
129 opener.addheaders = []
130 #print opener.addheaders
131 third = opener.open(req)
132 #print third.info()
133 #print third.headers.dict
134
135 if 'set-cookie' in third.headers.dict:
136 cookie = third.headers.dict['set-cookie']
137
138 r_Third = third.read()
139 #print r_Third
140
141 if r_Third.find('marq')<0:
142 okexit = okexit - 1
143 continue
144 else:
145 r_Second = r_Third
146
147 if r_Third.find('<input name=\"hdContinute\" id=\"hdContinute\" type=\"hidden\" value=\"1\" />')<0:
148 break
149
150 u_Forth = r_Third[r_Third.index('MyService.aspx?'):]
151 u_Forth = u_Forth[0:u_Forth.index('\"')]
152 u_Forth = u_Forth.replace('&','&')
153 #print u_Forth
154
155 vs = r_Third[r_Third.index('__VIEWSTATE'):]
156 vs = vs[len('__VIEWSTATE\" value=\"'):]
157 vs = vs[0:vs.index('\"')]
158 protestDict['__VIEWSTATE'] = vs
159
160 hdid = r_Third[r_Third.index('id=\"hdID\" type=\"hidden\" value=\"'):]
161 hdid = hdid[len('id=\"hdID\" type=\"hidden\" value=\"'):]
162 hdid = hdid[0:hdid.index('\"')]
163 protestDict['hdID'] = hdid
164
165 hdold = r_Third[r_Third.index('name=\"hdOld\" type=\"text\" value=\"'):]
166 hdold = hdold[len('name=\"hdOld\" type=\"text\" value=\"'):]
167 hdold = hdold[0:hdold.index('\"')]
168 protestDict['hdOld'] = hdold
169
170 req = urllib2.Request(url='https://forum.cmbchina.com/pcs/'+u_Forth)
171 pd = urllib.urlencode(protestDict)
172 pd = pd+'&btnSend=%B7%A2+%CB%CD'
173 #print '\"\"\"\"\"\n\n'
174 #print pd
175 #print '\"\"\"\"\"\n\n'
176 #print cookie
177 #print '\"\"\"\"\"\n\n'
178 req.add_data(pd)
179 req.add_header('User-Agent', c_UA)
180 req.add_header('Referer', 'https://forum.cmbchina.com/pcs/'+u_Forth)
181 req.add_header('Connection','Keep-Alive')
182 req.add_header('Cache-Control','no-cache')
183 req.add_header('Content-Type', 'application/x-www-form-urlencoded')
184 req.add_header('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*');
185 req.add_header('UA-CPU', 'x86')
186 req.add_header('Accept-Encoding', 'gzip, deflate')
187 if len(cookie)>0:
188 req.add_header('Cookie', cookie[0:cookie.find(';')])
189
190 sleep(20)
191
192 opener = urllib2.build_opener(SmartRedirectHandler())
193 opener.addheaders = []
194 forth = opener.open(req)
195 #print forth.info()
196 #print forth.headers.dict
197
198 r_Forth = forth.read()
199
200 if len(debug)>0:
201 of = open(debug+'/'+strftime("%d_%b_%Y_%H_%M_%S_FORTH.log", gmtime()), 'w')
202 of.write(r_Forth)
203 of.close()
204
205 #print 'Protest FIN.'