bugs fixed.

master
CHUN YU YAO 2023-01-11 22:26:49 +08:00
parent b2ead02346
commit ad14b98fc7
1 changed files with 27 additions and 18 deletions

View File

@ -40,7 +40,10 @@ warnings.simplefilter('ignore',InsecureRequestWarning)
# ocr # ocr
import base64 import base64
import ddddocr try:
import ddddocr
except Exception as exc:
pass
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
@ -1640,24 +1643,25 @@ def tixcraft_manully_keyin_verify_code(driver, ocr_answer = ""):
#PS: credit to LinShihJhang's share #PS: credit to LinShihJhang's share
def tixcraft_auto_ocr(driver, ocr): def tixcraft_auto_ocr(driver, ocr):
print("start to ddddocr") print("start to ddddocr")
try: orc_answer = None
row_text = select_obj.first_selected_option.text if not ocr is None:
except Exception as exc: try:
pass form_verifyCode_base64 = driver.execute_async_script("""
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var img = document.getElementById('yw0');
canvas.height = img.naturalHeight;
canvas.width = img.naturalWidth;
context.drawImage(img, 0, 0);
form_verifyCode_base64 = driver.execute_async_script(""" callback = arguments[arguments.length - 1];
var canvas = document.createElement('canvas'); callback(canvas.toDataURL());
var context = canvas.getContext('2d'); """)
var img = document.getElementById('yw0'); img_base64 = base64.b64decode(form_verifyCode_base64.split(',')[1])
canvas.height = img.naturalHeight; orc_answer = ocr.classification(img_base64)
canvas.width = img.naturalWidth; except Exception as exc:
context.drawImage(img, 0, 0); pass
callback = arguments[arguments.length - 1];
callback(canvas.toDataURL());
""")
img_base64 = base64.b64decode(form_verifyCode_base64.split(',')[1])
orc_answer = ocr.classification(img_base64)
if not orc_answer is None: if not orc_answer is None:
print("orc_answer:", orc_answer) print("orc_answer:", orc_answer)
if len(orc_answer)==4: if len(orc_answer)==4:
@ -1665,6 +1669,7 @@ def tixcraft_auto_ocr(driver, ocr):
else: else:
tixcraft_manully_keyin_verify_code(driver, "") tixcraft_manully_keyin_verify_code(driver, "")
def tixcraft_ticket_main(driver, config_dict, ocr): def tixcraft_ticket_main(driver, config_dict, ocr):
is_finish_checkbox_click = False is_finish_checkbox_click = False
auto_check_agree = config_dict["auto_check_agree"] auto_check_agree = config_dict["auto_check_agree"]
@ -5123,7 +5128,11 @@ def main():
if debugMode: if debugMode:
print("Start to looping, detect browser url...") print("Start to looping, detect browser url...")
ocr = ddddocr.DdddOcr() ocr = None
try:
ocr = ddddocr.DdddOcr()
except Exception as exc:
pass
while True: while True:
time.sleep(0.1) time.sleep(0.1)