Skip to content

Commit

Permalink
added GeeTest solve support
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Oct 29, 2021
1 parent b801c4c commit b3b4b89
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
max-parallel: 4
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.9]
python-version: [3.7, 3.9]

steps:
- uses: actions/checkout@v1
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pip install capmonster_python
- Recaptcha v3
- Fun Captcha
- HCaptcha
- GeeTest

Usage examples
-
Expand All @@ -45,6 +46,17 @@ result = capmonster.join_task_result(task_id)
print(result.get("gRecaptchaResponse"))
```

#### GeeTest
```python
from capmonster_python import GeeTestTask

capmonster = GeeTestTask("API_KEY")
task_id = capmonster.create_task("website_url", "gt", "challenge")
result = capmonster.join_task_result(task_id)
print(result.get("validate"))
print(result.get("seccode"))
```

For other examples and api documentation please visit [wiki](https://github.com/alperensert/capmonster_python/wiki)

### Migration from 1.3.2 to 2.x
Expand Down
1 change: 1 addition & 0 deletions capmonster_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from .recaptcha_v3 import RecaptchaV3Task
from .hcaptcha import HCaptchaTask
from .image_to_text import ImageToTextTask
from .gee_test import GeeTestTask
from .utils import CapmonsterException
24 changes: 24 additions & 0 deletions capmonster_python/gee_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from .capmonster import UserAgent


class GeeTestTask(UserAgent):
def __init__(self, client_key):
super(GeeTestTask, self).__init__(client_key)

def create_task(self, website_url: str, gt: str, challenge: str,
api_server_subdomain: str = None, get_lib: str = None):
data = {
"clientKey": self._client_key,
"task": {
"type": "GeeTestTask",
"websiteURL": website_url,
"gt": gt,
"challenge": challenge
}
}
data, is_user_agent = self._add_user_agent(data)
if api_server_subdomain:
data["task"]["geetestApiServerSubdomain"] = api_server_subdomain
if get_lib:
data["task"]["geetestGetLib"] = get_lib
return self._make_request("createTask", data).get("taskId")
33 changes: 33 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import unittest
import requests
from inspect import stack
from os import environ
from capmonster_python import *
Expand Down Expand Up @@ -178,5 +180,36 @@ def test_invisible_hcaptcha(self):
del solution, task_id


class TestGeeTest(unittest.TestCase):
def __init__(self, *args, **kwargs) -> None:
super(TestGeeTest, self).__init__(*args, **kwargs)
self.captcha = GeeTestTask(client_key)

def getProperties(self):
r = requests.get("https://2captcha.com/tr/demo/geetest").text
return (re.search("gt: '(.+?)'", r).group(1), re.search("challenge: '(.+?)'", r).group(1))

def test_proxyless_geetest(self):
gt, challenge = self.getProperties()
task_id = self.captcha.create_task(website_url="https://2captcha.com/tr/demo/geetest", gt=gt, challenge=challenge)
self.assertIs(type(task_id), int)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("validate", solution)
self.assertIn("seccode", solution)
del solution, task_id

def test_proxy_geetest(self):
self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4])
gt, challenge = self.getProperties()
task_id = self.captcha.create_task(website_url="https://2captcha.com/tr/demo/geetest", gt=gt, challenge=challenge)
self.assertIs(type(task_id), int)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("validate", solution)
self.assertIn("seccode", solution)
self.captcha.disable_proxy()
del solution, task_id

if __name__ == "__main__":
unittest.main()

0 comments on commit b3b4b89

Please sign in to comment.