-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(BrowserTool): add captcha detection
- Loading branch information
Showing
9 changed files
with
244 additions
and
24 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncio | ||
|
||
from npiai import BrowserTool, HITL | ||
from npiai.utils.test_utils import DebugContext | ||
|
||
|
||
class TestHITL(HITL): | ||
async def confirm( | ||
self, | ||
tool_name: str, | ||
message: str, | ||
default=False, | ||
) -> bool: | ||
print(f"[HITL] confirm: {message=}, {default=}") | ||
return True | ||
|
||
async def input( | ||
self, | ||
tool_name: str, | ||
message: str, | ||
default="", | ||
) -> str: | ||
print(f"[HITL] input: {message=}, {default=}") | ||
return "input" | ||
|
||
async def select( | ||
self, | ||
tool_name: str, | ||
message: str, | ||
choices: list[str], | ||
default="", | ||
) -> str: | ||
print(f"[HITL] select: {message=}, {choices=}, {default=}") | ||
return "select" | ||
|
||
async def web_interaction( | ||
self, | ||
tool_name: str, | ||
message: str, | ||
url: str, | ||
) -> str: | ||
print(f"[HITL] web_interaction: {message=}, {url=}") | ||
return "web_interaction" | ||
|
||
|
||
urls = [ | ||
"https://www.google.com/recaptcha/api2/demo", | ||
"https://nopecha.com/captcha/turnstile", | ||
"https://github.com/login", | ||
"https://google.com", | ||
] | ||
|
||
|
||
async def main(): | ||
ctx = DebugContext() | ||
ctx.use_hitl(TestHITL()) | ||
|
||
async with BrowserTool() as tool: | ||
for url in urls: | ||
await tool.load_page(ctx, url) | ||
captcha_type = await tool.detect_captcha(ctx) | ||
print(f"{url}: {captcha_type}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.