autofangche/main.py
2025-08-10 12:17:08 +08:00

81 lines
2.3 KiB
Python

import datetime
import os
import time
from playwright import sync_api
from requests import get
from logger import logger
os.makedirs("log", exist_ok=True)
TOKENAPI = "/api/auth/hik/token"
def TokenData():
return get(f"https://lida.mingliqiye.com{TOKENAPI}")
p = sync_api.sync_playwright().start()
browser = p.chromium.launch(channel="msedge", headless=False)
context = browser.new_context()
cookies_data = [
{
'name': 'Admin-Token',
'value': TokenData().json()['Data']['token'],
'domain': 'lida.haikewulian.com',
'path': '/',
'expires': (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp(),
'httpOnly': False,
'secure': False,
'sameSite': 'Lax'
},{
'name': 'Auth',
'value': 'eyJSZW1iZXJNZSI6eyJzdGF0ZSI6dHJ1ZSwidXNlcm5hbWUiOiJsaWRhIiwicGFzc3dvcmQiOiIwNTA2MDdqaCJ9LCJUb2tlbiI6eyJ0eXBlIjoiIiwiZGF0YSI6IiJ9fQ==',
'domain': 'lida.mingliqiye.com',
'path': '/',
'expires': (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp(),
'httpOnly': False,
'secure': False,
'sameSite': 'Lax'
},
]
context.add_cookies(cookies_data)
page = context.new_page()
page.goto("http://lida.haikewulian.com/weighthouse/poundList")
def taigan():
get("http://192.168.127.245:8184/gate-operate/?a=1&channelNo=CNZEQ070108WE06")
def fangche():
page.locator(".btn1").click()
time.sleep(0.1)
page.locator('button[class="el-button el-button--success el-button--medium"]').click()
print(page.locator('input[placeholder="请输入车牌号"]').text_content())
pass
fangche()
def bucai():
page.locator(".btn2").click()
time.sleep(5)
pass
haiguanold = ''
while True:
time.sleep(1)
haiguan = page.locator('span[class="el-tooltip call-tip el-tag el-tag--medium el-tag--light"]').text_content()
if haiguan != haiguanold:
haiguanold = haiguan
logger.info(haiguan)
if "车辆状态错误:车辆当前状态为【已入场】" in haiguan:
fangche()
taigan()
elif "海关放行" in haiguan:
fangche()
elif "读取不到货物运输批次提单信息" in haiguan:
fangche()
taigan()
elif "过卡车辆称重与申报空车重量不符:过卡车辆称重与申报空车重量不符" in haiguan:
bucai()