Created
February 27, 2020 02:03
-
-
Save cysin/0d7ed0df1e2b1f3661917d77188bbc5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*- coding: utf-8 -*- | |
import numpy as np | |
import sys,os | |
reload(sys) | |
sys.setdefaultencoding("utf-8") | |
import argparse | |
caffe_root = '/root/work/caffe/' | |
sys.path.insert(0, caffe_root + 'python') | |
os.environ['GLOG_minloglevel'] = '3' | |
import caffe | |
import google.protobuf.text_format | |
import time | |
import threading | |
import requests | |
import logging | |
import json | |
import base64 | |
import random | |
import math | |
import pprint as pp | |
import cv2 | |
class worker (threading.Thread): | |
def __init__(self, data): | |
threading.Thread.__init__(self) | |
self.data = data | |
caffe.set_mode_gpu() | |
self.net = caffe.Net('captcha.net', 'captcha.model', caffe.TEST) | |
self.debug = False#False | |
def run(self): | |
while True: | |
#http://kzyynew.qingdao.gov.cn:81/kz/postPage | |
#http://kzyynew.qingdao.gov.cn:81/kz/sfPage | |
#http://kzyynew.qingdao.gov.cn:81/kz/getAreaList | |
url = 'http://kzyynew.qingdao.gov.cn:81/kz/captcha?' + str(random.random()) | |
r = requests.get(url) | |
cookies = r.cookies | |
if self.debug: | |
with open('captcha.jpg', 'wb+') as f: | |
f.write(r.content) | |
# get captcha code | |
np_data = np.asarray(bytearray(r.content), dtype="uint8") | |
img = cv2.imdecode(np_data, 0) | |
self.net.blobs['data'].data[...] = img | |
r = self.net.forward() | |
d = r.values()[0].flatten().reshape((4, 30)) | |
probs = np.amax(d, axis=1) | |
idx = np.argmax(d, axis=1) | |
#pp.pprint(probs) | |
codes = ['2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','M','N','P','Q','R','T','U','V','W','X','Y','S'] | |
capvals = np.take(codes, idx) | |
captcha_code = "".join(capvals) | |
payload = self.data | |
payload['capval'] = captcha_code | |
if payload['ordertype'] == 1: | |
post_url = 'http://kzyynew.qingdao.gov.cn:81/kz/addYdorder?capval='+str(captcha_code) | |
else: | |
post_url = 'http://kzyynew.qingdao.gov.cn:81/kz/addSforder?capval='+str(captcha_code) | |
r = requests.post(post_url, data=json.dumps(payload), cookies=cookies) | |
out = payload['name'] + ' - ' + payload['address'] + ' - ' + r.text | |
print(out) | |
break | |
if __name__ == '__main__': | |
logging.basicConfig(format='%(asctime)s\t%(message)s', filename='log.txt', level=logging.DEBUG) | |
logging.getLogger().setLevel(logging.DEBUG) | |
requests_log = logging.getLogger("requests.packages.urllib3") | |
requests_log.setLevel(logging.DEBUG) | |
requests_log.propagate = True | |
user_data = ( | |
{"address":"xxx","name":"张三","mobile":"18666666666","code":"370202111111111111","area":"市南区","street":"湛山街道办事处","capval":"77jo","ordertype":1}, | |
) | |
threads = [] | |
for data in user_data: | |
t = worker(data) | |
threads.append(t) | |
for t in threads: | |
t.start() | |
for t in threads: | |
t.join() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment