Created
February 10, 2020 08:16
-
-
Save cysin/f4a7c69676de600999121f03b05300ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = True#False | |
def run(self): | |
#requests.get("http://kzyynew.qingdao.gov.cn:81/kz/listYd") | |
url = 'http://kzyynew.qingdao.gov.cn:81/kz/captcha?' + str(random.random()) | |
#url = 'http://kzyynew.qingdao.gov.cn:81/authPage/orderPage' | |
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) | |
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 | |
r = requests.get('http://kzyynew.qingdao.gov.cn:81/kz/addYdorder', params=payload, cookies=cookies) | |
out = payload['name'] + ' - ' + payload['ydname'] + ' - ' + r.text | |
print(out) | |
if __name__ == '__main__': | |
# You must initialize logging, otherwise you'll not see debug output. | |
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 = ( | |
{'code': '370202xxxxxxxxxxxx', 'mobile': '185xxxxxxxx','name': 'xxx','ydid': '145','ydname': '十七分店','capval': '','ydaddress': '2号网点'}, | |
) | |
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