commit
8b110b0e74
|
@ -0,0 +1,38 @@
|
|||
import requests
|
||||
import json
|
||||
import base64
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
class NonBrowser():
|
||||
def __init__(self) -> None:
|
||||
self.Session = requests.session()
|
||||
self.url = "https://tixcraft.com/ticket/captcha"
|
||||
self.refresh_url = "https://tixcraft.com/ticket/captcha?refresh=1"
|
||||
|
||||
def Set_cookies(self,cookies:dict):
|
||||
for cookie in cookies:
|
||||
self.Session.cookies.set(cookie["name"],cookie["value"])
|
||||
return True
|
||||
|
||||
def set_headers(self,header:str):
|
||||
self.Session.headers = header
|
||||
|
||||
def Request_Captcha(self):
|
||||
img = Image.open(BytesIO(self.Session.get(self.url, stream = True).content))
|
||||
output_buffer = BytesIO()
|
||||
img.save(output_buffer, format='JPEG')
|
||||
binary_data = output_buffer.getvalue()
|
||||
base64_data = base64.b64encode(binary_data)
|
||||
return base64_data
|
||||
|
||||
def Request_Refresh_Captcha(self) -> str:
|
||||
try:
|
||||
result = self.Session.get(self.refresh_url, stream = True)
|
||||
if result.status_code == 200:
|
||||
json_data = json.loads(result.text)
|
||||
return json_data.get("url","")
|
||||
else:
|
||||
return ""
|
||||
except Exception as e:
|
||||
return ""
|
|
@ -1608,6 +1608,12 @@ def tixcraft_verify(driver, presale_code):
|
|||
|
||||
return ret
|
||||
|
||||
def tixcraft_change_captcha(driver,url):
|
||||
try:
|
||||
driver.execute_script(f"document.querySelector('.verify-img').children[0].setAttribute('src','{url}');")
|
||||
except Exception as exc:
|
||||
print("edit captcha element fail")
|
||||
|
||||
def tixcraft_toast(driver, message):
|
||||
toast_element = None
|
||||
try:
|
||||
|
@ -1686,31 +1692,23 @@ def tixcraft_reload_captcha(driver):
|
|||
#PS: credit to LinShihJhang's share
|
||||
def tixcraft_auto_ocr(driver, ocr, ocr_captcha_with_submit, ocr_captcha_force_submit, previous_answer):
|
||||
print("start to ddddocr")
|
||||
from NonBrowser import NonBrowser
|
||||
|
||||
is_need_redo_ocr = False
|
||||
is_form_sumbited = False
|
||||
|
||||
orc_answer = None
|
||||
|
||||
if not ocr is None:
|
||||
Non_Browser = NonBrowser()
|
||||
Non_Browser.Set_cookies(driver.get_cookies())
|
||||
img_base64 = base64.b64decode(Non_Browser.Request_Captcha())
|
||||
try:
|
||||
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);
|
||||
|
||||
callback = arguments[arguments.length - 1];
|
||||
callback(canvas.toDataURL());
|
||||
""")
|
||||
img_base64 = base64.b64decode(form_verifyCode_base64.split(',')[1])
|
||||
orc_answer = ocr.classification(img_base64)
|
||||
except Exception as exc:
|
||||
pass
|
||||
else:
|
||||
print("ddddocr is None")
|
||||
|
||||
|
||||
if not orc_answer is None:
|
||||
orc_answer = orc_answer.strip()
|
||||
print("orc_answer:", orc_answer)
|
||||
|
|
Loading…
Reference in New Issue