From 49a2f3024aaa77c997c2f42029be6fe7a97626ff Mon Sep 17 00:00:00 2001 From: protokey Date: Tue, 13 Oct 2026 20:21:17 +0400 Subject: [PATCH] =?UTF-8?q?feature:=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D0=B5=20inner=5Ftext;=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D1=8B=20v2=20=D0=B2=20test=5Fmain.http?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/actions.py | 8 ++++++++ src/api/schemas.py | 1 + tests/test_main.http | 26 ++++++++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/api/actions.py b/src/api/actions.py index 0b30b2c..e67993d 100644 --- a/src/api/actions.py +++ b/src/api/actions.py @@ -1,4 +1,5 @@ import asyncio +import re import time from patchright.async_api import Page @@ -71,6 +72,13 @@ async def inner_html(page: Page, act: ActionRequest, **kwargs) -> str | None: return await element.inner_html() +@register +async def inner_text(page: Page, act: ActionRequest, **kwargs) -> str | None: + html_source = await inner_html(page, act, **kwargs) + text = re.sub(r"<[^>]+>", "", html_source) + return text + + @register async def wait_for(page: Page, act: ActionRequest, **kwargs) -> str | None: await page.wait_for_selector(act.selector, timeout=act.timeout * 1000) diff --git a/src/api/schemas.py b/src/api/schemas.py index a8780b8..c68a89b 100644 --- a/src/api/schemas.py +++ b/src/api/schemas.py @@ -17,6 +17,7 @@ _REQUIRED_FIELDS: dict[str, tuple[str, ...]] = { "click": ("selector",), "submit": ("selector",), "inner_html": ("selector",), + "inner_text": ("selector",), "wait_for": ("selector",), "pass_challenge": (), } diff --git a/tests/test_main.http b/tests/test_main.http index afbc242..be5b8df 100644 --- a/tests/test_main.http +++ b/tests/test_main.http @@ -109,19 +109,29 @@ X-API-Key: ### 2f2100be-6ce7-40d5-bae5-61424b2504c8 -POST http://127.0.0.1:8000/v1/solve +POST http://localhost:8002/v2/tasks Accept: application/json Content-Type: application/json X-API-Key: { - "url": "https://ifconfig.me/", - "proxy": "http://7LLkWF:yecUzT@200.10.32.226:8000", - "actions": [ - {"type": "wait_for", "selector": "#ip_address", "timeout": 10}, - {"type": "inner_html", "selector": "#ip_address"} - ] + "url": "https://freelancehunt.com/", + "proxy": "http://BQLo3X:poqAWX@168.81.43.154:8000", + "actions": [ + { + "type": "inner_text", + "selector": "//section[@class='hero']//div[@class='hero__content']/h2/span[2]" + } + ], + "captcha_type": "cloudflare", + "browser_idle_timeout": 0 } +### -### b8f770a3-38c2-45f2-944b-2703798e3503 +GET http://localhost:8002/v2/tasks/4d8105f8-93a8-43ee-aa6e-db917451363b +Accept: application/json +Content-Type: application/json +X-API-Key: + +###