2023-01-12 15:30:34 +00:00
|
|
|
import base64
|
2023-10-30 00:15:20 +00:00
|
|
|
import json
|
2023-01-12 15:30:34 +00:00
|
|
|
from io import BytesIO
|
|
|
|
|
2023-10-30 00:15:20 +00:00
|
|
|
import requests
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2023-01-12 15:30:34 +00:00
|
|
|
class NonBrowser():
|
2023-01-14 09:53:32 +00:00
|
|
|
def __init__(self, domain_name = "tixcraft.com") -> None:
|
2023-01-12 15:30:34 +00:00
|
|
|
self.Session = requests.session()
|
2023-01-14 09:53:32 +00:00
|
|
|
self.Set_Domain(domain_name)
|
2023-01-12 15:30:34 +00:00
|
|
|
|
2023-04-05 12:47:44 +00:00
|
|
|
def Set_cookies(self, cookies:dict):
|
|
|
|
ret = False
|
|
|
|
if not cookies is None:
|
|
|
|
for cookie in cookies:
|
|
|
|
self.Session.cookies.set(cookie["name"],cookie["value"])
|
|
|
|
ret = True
|
|
|
|
return ret
|
2023-01-12 15:30:34 +00:00
|
|
|
|
2023-04-05 12:47:44 +00:00
|
|
|
def set_headers(self, header:str):
|
2023-01-12 15:30:34 +00:00
|
|
|
self.Session.headers = header
|
|
|
|
|
2023-01-14 09:53:32 +00:00
|
|
|
def Set_Domain(self, domain_name, captcha_url="ticket/captcha", refresh_url="ticket/captcha?refresh=1"):
|
|
|
|
self.url = "https://%s/%s" % (domain_name, captcha_url)
|
|
|
|
self.refresh_url = "https://%s/%s" % (domain_name, refresh_url)
|
|
|
|
|
2023-01-12 15:30:34 +00:00
|
|
|
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:
|
2023-01-12 15:49:20 +00:00
|
|
|
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 ""
|