def get_student_info(id,name,idcard): id = str(id) if int(id[2])>3: base_url = 'http://xxjw.hnust.cn/xxjw' else : base_url = 'http://kdjw.hnust.cn/kdjw' # if int(id[2])>3: base_url = 'http://localhost:2167/xxjw' # else : base_url = 'http://localhost:2169/kdjw' opener = requests.Session() url_img = base_url+'/verifycode.servlet' try: opener.get(base_url,timeout=1) except: return {'error':True,'msg':"7.服务器网络故障,可能查询的人太多了,亲再等等"} for i in range(5): try: img = opener.get(url_img,timeout=1).content except : continue code = ocr.recognize(img) url_submit = base_url+'/xscjcx_check.jsp' payload = { 'xsxm':name, 'xssfzh':idcard, 'yzm':code, } try: res = opener.post(url_submit,payload,timeout=1).text except : continue if 'yzm_guoq' in res : return {'error':True,'msg':"1.验证码过期"} if 'yzm_cuowu' in res : continue if 'notQueryXs' in res : return {'error':True,'msg':"3.未找到您输入信息的学生"} if 'systemError' in res : return {'error':True,'msg':"4.您访问的功能出现错误"} url_scope = base_url+'/xscjcx.jsp?yzbh=' + res[-36:-4] try: html = opener.get(url_scope,timeout=1).text except : continue if not re.search('\d{10}',html) : return {'error':True,'msg':"5.登陆成功了,但是似乎没有你的信息哦"} return htmlToJson.htmlToJson(html) return {'error':True,'msg':"8.服务器网络故障,可能查询的人太多了,亲再等等"}
def call_detect(): global img, text net = build_ssd('test', 300, 3) net.load_state_dict( torch.load('ssd300_0712_5000.pth', map_location=lambda storage, loc: storage)) transform = BaseTransform(net.size, (104 / 256.0, 117 / 256.0, 123 / 256.0)) new_images = detect(img, net.eval(), transform) text = recognize(new_images)
def get_student_info(id, name, idcard): id = str(id) if int(id[2]) > 3: base_url = 'http://xxjw.hnust.cn/xxjw' else: base_url = 'http://kdjw.hnust.cn/kdjw' # if int(id[2])>3: base_url = 'http://localhost:2167/xxjw' # else : base_url = 'http://localhost:2169/kdjw' opener = requests.Session() url_img = base_url + '/verifycode.servlet' try: opener.get(base_url, timeout=1) except: return {'error': True, 'msg': "7.服务器网络故障,可能查询的人太多了,亲再等等"} for i in range(5): try: img = opener.get(url_img, timeout=1).content except: continue code = ocr.recognize(img) url_submit = base_url + '/xscjcx_check.jsp' payload = { 'xsxm': name, 'xssfzh': idcard, 'yzm': code, } try: res = opener.post(url_submit, payload, timeout=1).text except: continue if 'yzm_guoq' in res: return {'error': True, 'msg': "1.验证码过期"} if 'yzm_cuowu' in res: continue if 'notQueryXs' in res: return {'error': True, 'msg': "3.未找到您输入信息的学生"} if 'systemError' in res: return {'error': True, 'msg': "4.您访问的功能出现错误"} url_scope = base_url + '/xscjcx.jsp?yzbh=' + res[-36:-4] try: html = opener.get(url_scope, timeout=1).text except: continue if not re.search('\d{10}', html): return {'error': True, 'msg': "5.登陆成功了,但是似乎没有你的信息哦"} return htmlToJson.htmlToJson(html) return {'error': True, 'msg': "8.服务器网络故障,可能查询的人太多了,亲再等等"}
def login(): max_fail_time = 20 fail_time = 0 options = webdriver.ChromeOptions() options.binary_location = '/usr/bin/google-chrome' options.add_argument('headless') options.add_argument('--window-size=800,600') driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=options) not_login = True driver.execute_script('window.open("");') # open a new tab for CAPTCHA while not_login: if fail_time > max_fail_time: notify('登录失败') sys.exit() driver.switch_to.window( driver.window_handles[0]) # switch to login page driver.get( 'http://www.pss-system.gov.cn/sipopublicsearch/portal/uilogin-forwardLogin.shtml' ) print(driver.get_cookie('IS_LOGIN')['value']) try: WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'j_validation_code'))) except TimeoutException: fail_time += 1 sleep(fail_time**2) continue driver.find_element_by_id('j_username').send_keys('a729918410') driver.find_element_by_id('j_password_show').send_keys('HAF4cu0HkiaW') driver.switch_to.window( driver.window_handles[1]) # switch to code image while True: driver.get( 'http://www.pss-system.gov.cn/sipopublicsearch/portal/login-showPic.shtml' ) driver.save_screenshot('f**k.png') code = recognize() if code != 'wtf': break driver.switch_to.window( driver.window_handles[0]) # switch to login page driver.find_element_by_id('j_validation_code').send_keys(code) driver.execute_script('login();') try: WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.CLASS_NAME, 'ui-dialog-content'))) error_dialog = driver.find_element_by_class_name( 'ui-dialog-content').text if error_dialog.find('密码') != -1: print(error_dialog) print('Password error. You are f****d') notify('用户名密码错误') sys.exit() if error_dialog.find('验证码') != -1: print(error_dialog) print('CAPTCHA error. Try again.') fail_time += 1 sleep(fail_time**2) continue except TimeoutException: try: driver.find_element_by_id('globleBody') except NoSuchElementException: fail_time += 1 sleep(fail_time**2) continue print('Seems good.') if driver.get_cookie('IS_LOGIN')['value'] == 'true': print('Login success') not_login = False JSESSIONID = driver.get_cookie('JSESSIONID') WEE_SID = driver.get_cookie('WEE_SID') return { 'JSESSIONID': JSESSIONID['value'], 'WEE_SID': WEE_SID['value'] } else: fail_time += 1 sleep(fail_time**2) continue
i = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # pull_screenshot(i) # # now = time.time() # print "get screenshot", now - last_point # last_point = now # # im = Image.open("{}{}{}.png".format(origin_dir, img_ext, i)) im = d.screenshot() now = time.time() print "d.screenshot", now - last_point last_point = now res = recognize(im) print res now = time.time() print "recognize", now - last_point last_point = now url = "http://www.baidu.com/s?ie=UTF-8&wd=%s" % res browser.get(url) now = time.time() print "brower", now - last_point last_point = now print "total", now - start im.save("{}{}{}.png".format(origin_dir, img_ext, i)) browser.quit()
from ocr import recognize from parse import parse from solver import solve file = open("words.txt", "r") words = file.readlines() for i in range(len(words)): words[i] = words[i].upper().rstrip("\n") print("\nSolving for the words: " + str(words) + "\n") raw_text = recognize() print("Wordsearch out:") print(raw_text + "\n") rows = parse(raw_text) solves = [] for word in words: xs, ys = solve(word, rows) solves.append([xs, ys]) print("Solves:") print(solves) # print("Pretty print:") # print(rev_parse(display(rows, words, solves))) # TODO: Do pretty print