-
Notifications
You must be signed in to change notification settings - Fork 20
/
bank.py
executable file
·131 lines (101 loc) · 3.29 KB
/
bank.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
import json
import banks.static_data as data
import requests
# post url
post_url = 'https://pay.weixin.qq.com/index.php/core/applymentnew/query_bank_list'
# 请求结果
result = []
import queue
import threading
import time
import requests
# 1. 填写你的参数
ecc_csrf_token = ''
merchantId = ''
myCookie = ''
Referer = ''
# 2. # pyhton bank.py
taskQueue = queue.Queue()
workQueue = queue.Queue()
class FetchThread(threading.Thread):
def __init__(self, tQueue, wQueue):
threading.Thread.__init__(self)
self.tQueue = tQueue
self.wQueue = wQueue
def run(self):
while True:
bank = self.tQueue.get()
if bank is None:
break
try:
date_r= getBanks(bank)
result.extend(date_r)
# self.wQueue.put(date_r)
except Exception as e:
print(e)
self.tQueue.task_done()
class WorkThread(threading.Thread):
def __init__(self, wQueue):
threading.Thread.__init__(self)
self.wQueue = wQueue
def run(self):
while True:
text = self.wQueue.get()
if text is None:
break
self.wQueue.task_done()
start_time = time.time()
def getBanks(bank_id):
r = []
for p in data.city:
# print(p['name'],p['value'])
for c in p['children']:
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36',
'Cookie': myCookie,
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'pay.weixin.qq.com',
'Origin': 'https: // pay.weixin.qq.com',
'Referer': myReferer
}
resp = requests.post(post_url, headers=headers, data={
'bankId': bank_id,
'provinceId': p['value'],
'cityId': c['value'],
'mode': '5',
'ecc_csrf_token': ecc_csrf_token,
'merchantId': merchantId
})
resp.encoding = 'utf-8'
if resp.status_code == 200:
sub_banks = resp.json()['data']
for sub in sub_banks:
sub['provinceId'] = p['value']
sub['cityId'] = c['value']
sub['bankId'] = bank_id
r.append(sub)
if len(sub_banks) > 0:
print('bank_id', bank_id, 'provinceId', p['value'], 'cityId', c['value'], 'ok')
else:
print('bank_id', bank_id, 'provinceId', p['value'], 'cityId', c['value'], 'empty')
else:
print("error:", resp.status_code)
return r
def main():
for i in range(25):
t = FetchThread(taskQueue, workQueue)
t.setDaemon(True)
t.start()
for bank in data.banks:
taskQueue.put(bank['value'])
for i in range(6):
dt = WorkThread(workQueue)
dt.setDaemon(True)
dt.start()
workQueue.join()
taskQueue.join()
main()
with open("data/banks.txt", "w") as f:
f.write(json.dumps(result))
print("size=" + str(workQueue.qsize()))
print("task finished by {} seconds.".format(time.time() - start_time))