Skip to content

Commit e7c332c

Browse files
authored
- Added tencent method to solver.py (#80)
- Added captcha solution examples tencent.py and tencent_options.py - Added test test_tencent.py Signed-off-by: Maxim S <poplers24@gmail.com>
1 parent ba77ae8 commit e7c332c

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

examples/tencent.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
solver = TwoCaptcha(api_key)
17+
18+
try:
19+
result = solver.tencent(
20+
app_id="197322596",
21+
url="https://www.holla.world/random-video-chat#app"
22+
)
23+
24+
except Exception as e:
25+
sys.exit(e)
26+
27+
else:
28+
sys.exit('result: ' + str(result))

examples/tencent_options.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
import os
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
5+
6+
from twocaptcha import TwoCaptcha
7+
8+
# in this example we store the API key inside environment variables that can be set like:
9+
# export APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Linux or macOS
10+
# set APIKEY_2CAPTCHA=1abc234de56fab7c89012d34e56fa7b8 on Windows
11+
# you can just set the API key directly to it's value like:
12+
# api_key="1abc234de56fab7c89012d34e56fa7b8"
13+
14+
api_key = os.getenv('APIKEY_2CAPTCHA', 'YOUR_API_KEY')
15+
16+
17+
config = {
18+
'server': '2captcha.com', # can be also set to 'rucaptcha.com'
19+
'apiKey': api_key,
20+
'softId': 123,
21+
# 'callback': 'https://your.site/result-receiver', # if set, sovler with just return captchaId, not polling API for the answer
22+
'defaultTimeout': 120,
23+
'recaptchaTimeout': 600,
24+
'pollingInterval': 10,
25+
}
26+
27+
solver = TwoCaptcha(**config)
28+
29+
try:
30+
result = solver.tencent(app_id="197325555",
31+
url="https://your.site/result-receiver",
32+
# proxy={
33+
# 'type': 'HTTPS',
34+
# 'uri': 'ub6900fef552505bc-zone-custom-session-JcIHpmDKv-sessTime-1:ub6900fef552505bc@43.152.113.55:2333'
35+
# }
36+
)
37+
38+
except Exception as e:
39+
sys.exit(e)
40+
41+
else:
42+
sys.exit('result: ' + str(result))

tests/test_tencent.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
try:
6+
from .abstract import AbstractTest
7+
except ImportError:
8+
from abstract import AbstractTest
9+
10+
11+
class TencentTest(AbstractTest):
12+
13+
def test_all_params(self):
14+
params = {
15+
"app_id": "197322596",
16+
"url": "https://www.holla.world/random-video-chat#app"
17+
}
18+
19+
sends = {
20+
"method": "tencent",
21+
"app_id": "197322596",
22+
"pageurl": "https://www.holla.world/random-video-chat#app",
23+
}
24+
25+
return self.send_return(sends, self.solver.tencent, **params)
26+
27+
28+
if __name__ == '__main__':
29+
unittest.main()

twocaptcha/solver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,32 @@ def friendly_captcha(self, sitekey, url, **kwargs):
751751
**kwargs)
752752
return result
753753

754+
def tencent(self, app_id, url, **kwargs):
755+
'''Wrapper for solving Tencent captcha.
756+
757+
Parameters
758+
__________
759+
app_id : str
760+
The value of appId parameter in the website source code.
761+
url : str
762+
The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is
763+
available only for authenticated users.
764+
softId : int, optional
765+
ID of software developer. Developers who integrated their software with 2Captcha get reward: 10% of
766+
spendings of their software users.
767+
callback : str, optional
768+
URL for pingback (callback) response that will be sent when captcha is solved. URL should be registered on
769+
the server. More info here https://2captcha.com/2captcha-api#pingback.
770+
proxy : dict, optional
771+
{'type': 'HTTPS', 'uri': 'login:password@IP_address:PORT'}.
772+
'''
773+
774+
result = self.solve(app_id=app_id,
775+
url=url,
776+
method="tencent",
777+
**kwargs)
778+
return result
779+
754780
def cutcaptcha(self, misery_key, apikey, url, **kwargs):
755781
'''Wrapper for solving Friendly Captcha.
756782

0 commit comments

Comments
 (0)