Skip to content

Commit

Permalink
added GeeTest support
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Oct 29, 2021
1 parent b801c4c commit 00f79a0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 15 deletions.
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
14 changes: 14 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,19 @@ result = capmonster.join_task_result(task_id)
print(result.get("gRecaptchaResponse"))
```

#### GeeTest

```python
from capmonster_python import GeeTestTask

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

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 .geetest import GeeTestTask
from .utils import CapmonsterException
26 changes: 26 additions & 0 deletions capmonster_python/geetest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .capmonster import Proxy, UserAgent


class GeeTestTask(UserAgent, Proxy):
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)
data, is_proxy = self._is_proxy_task(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")

82 changes: 68 additions & 14 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import re
import requests
import unittest
from inspect import stack
from os import environ
from capmonster_python import *

client_key = environ.get("KEY")
proxy = environ.get("PROXY").split(",")
acceptable_error_codes = ["ERROR_CAPTCHA_UNSOLVABLE", "ERROR_MAXIMUM_TIME_EXCEED"]
acceptable_error_codes = ["ERROR_CAPTCHA_UNSOLVABLE", "ERROR_MAXIMUM_TIME_EXCEED", "ERROR_NO_SLOT_AVAILABLE"]


class TestImageToText(unittest.TestCase):
Expand Down Expand Up @@ -52,8 +54,8 @@ def __init__(self, *args, **kwargs):
}

def test_proxyless_recaptchav2(self):
task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level"
"=high", "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
cookies=self.dump_cookies)
self.assertIs(type(task_id), int)
solution = self.captcha.join_task_result(task_id)
Expand All @@ -62,17 +64,23 @@ def test_proxyless_recaptchav2(self):
del task_id, solution

def test_proxy_recaptchav2(self):
self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4])
task_id = self.captcha.create_task("https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level"
"=high", "6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
cookies=self.dump_cookies, no_cache=True)
self.assertIs(type(task_id), int)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("gRecaptchaResponse", solution)
self.captcha.disable_proxy()
self.captcha.reset_user_agent()
try:
self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
self.captcha.set_proxy(proxy[0], proxy[1], int(proxy[2]), proxy[3], proxy[4])
task_id = self.captcha.create_task(
"https://lessons.zennolab.com/captchas/recaptcha/v2_simple.php?level=high",
"6Lcg7CMUAAAAANphynKgn9YAgA4tQ2KI_iqRyTwd",
cookies=self.dump_cookies, no_cache=True)
self.assertIs(type(task_id), int)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("gRecaptchaResponse", solution)
self.captcha.disable_proxy()
self.captcha.reset_user_agent()
except CapmonsterException as err:
if any(err.error_code in s for s in acceptable_error_codes):
print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code))
pass


class TestRecaptchaV3(unittest.TestCase):
Expand Down Expand Up @@ -178,5 +186,51 @@ def test_invisible_hcaptcha(self):
del solution, task_id


class TestGeeTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
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_proxy_geetest(self):
try:
self.captcha.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
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)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("challenge", solution)
self.assertIn("seccode", solution)
self.assertIn("validate", solution)
self.captcha.disable_proxy()
self.captcha.reset_user_agent()
del solution, task_id
except CapmonsterException as err:
if any(err.error_code in s for s in acceptable_error_codes):
print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code))
pass

def test_proxyless_geetest(self):
try:
gt, challenge = self.getProperties()
task_id = self.captcha.create_task(website_url="https://2captcha.com/tr/demo/geetest",
gt=gt, challenge=challenge)
solution = self.captcha.join_task_result(task_id)
self.assertIs(type(solution), dict)
self.assertIn("challenge", solution)
self.assertIn("seccode", solution)
self.assertIn("validate", solution)
del solution, task_id
except CapmonsterException as err:
if any(err.error_code in s for s in acceptable_error_codes):
print("Raised error code in " + stack()[0][3] + " but it's ok: {}".format(err.error_code))
pass


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

0 comments on commit 00f79a0

Please sign in to comment.