chore: общие правки
This commit is contained in:
1 parent
c0d2d98911
commit
1a45976356
4 files changed
+32
-17
No files matched your search
+22
-11
@@ -25,25 +25,36 @@ async def click(page: Page, act: ActionRequest) -> str | None:
|
||||
...
|
||||
|
||||
|
||||
@register
|
||||
async def inner_html(page: Page, act: ActionRequest) -> str | None:
|
||||
assert act.selector
|
||||
element = await page.query_selector(act.selector)
|
||||
return await element.inner_html()
|
||||
|
||||
|
||||
@register
|
||||
async def wait_for(page: Page, act: ActionRequest) -> str | None:
|
||||
try:
|
||||
assert act.selector
|
||||
await page.wait_for_selector(act.selector, timeout=act.timeout * 1000)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
else:
|
||||
return None
|
||||
assert act.selector
|
||||
assert 1 <= act.timeout <= 7200
|
||||
await page.wait_for_selector(act.selector, timeout=act.timeout * 1000)
|
||||
|
||||
|
||||
async def execute(page: Page, actions: list[ActionRequest]) -> list[str]:
|
||||
async def execute(page: Page, actions: list[ActionRequest]) -> list[dict]:
|
||||
actions_result = []
|
||||
for act in actions:
|
||||
new_line = {
|
||||
"type": act.type,
|
||||
}
|
||||
try:
|
||||
await _actions[act.type](page, act)
|
||||
result = await _actions[act.type](page, act)
|
||||
except Exception as e:
|
||||
actions_result.append({"type": act.type, "ok": "false", "error": str(e)})
|
||||
new_line["ok"] = False
|
||||
new_line["result"] = str(e)
|
||||
actions_result.append(new_line)
|
||||
break
|
||||
else:
|
||||
actions_result.append({"type": act.type, "ok": "true"})
|
||||
new_line["ok"] = True
|
||||
if result:
|
||||
new_line["result"] = result
|
||||
actions_result.append(new_line)
|
||||
return actions_result
|
||||
@@ -24,3 +24,4 @@ class SolveRequest(BaseModel):
|
||||
timeout: int | None = None
|
||||
screen: str = "1280x720"
|
||||
user_agent: str | None = None
|
||||
html: bool = False
|
||||
+6
-3
@@ -140,10 +140,13 @@ async def solve(
|
||||
)
|
||||
|
||||
BROWSER_SLOTS += 1
|
||||
return {
|
||||
result = {
|
||||
"status": ["err", "ok"][status],
|
||||
"html": html,
|
||||
"cookies": cookies,
|
||||
"actions": actions_result,
|
||||
"error": error,
|
||||
}
|
||||
if payload.html:
|
||||
result["html"] = html
|
||||
if error:
|
||||
result["error"] = error
|
||||
return result
|
||||
@@ -37,14 +37,15 @@ POST http://127.0.0.1:8000/v1/solve
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
X-API-Key: <key>
|
||||
Cookie: session_id=b8f770a3-38c2-45f2-944b-2703798e3503; Path=/; SameSite=lax
|
||||
Cookie: session_id=2f2100be-6ce7-40d5-bae5-61424b2504c8; Path=/; SameSite=lax
|
||||
|
||||
|
||||
{
|
||||
"url": "https://browserleaks.com/canvas",
|
||||
"proxy": "-",
|
||||
"actions": [
|
||||
{"type": "wait_for", "selector": "#gl-image-src1", "timeout": 30}
|
||||
{"type": "wait_for", "selector": "#canvas-hash", "timeout": 10},
|
||||
{"type": "inner_html", "selector": "#canvas-hash"}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -53,7 +54,6 @@ POST http://127.0.0.1:8000/v1/solve
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
X-API-Key: <key>
|
||||
Cookie: session_id=b8f770a3-38c2-45f2-944b-2703798e3503; Path=/; SameSite=lax
|
||||
|
||||
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user