-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
71 deletions.
There are no files selected for viewing
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,68 @@ | ||
import time | ||
|
||
import loguru | ||
import requests | ||
from retry import retry | ||
|
||
from config import cookies_config_path, global_cookieManager | ||
from geetest.Validator import Validator | ||
from util.bili_request import BiliRequest | ||
|
||
|
||
class CapSolverValidator(Validator): | ||
def __init__(self): | ||
self.cookieManager = global_cookieManager | ||
pass | ||
|
||
@retry() | ||
def validate(self, appkey, gt, challenge, referer="http://127.0.0.1:7860/") -> str: | ||
if appkey is None or appkey == "": | ||
appkey = self.cookieManager.get_config_value("appkey", "") | ||
else: | ||
self.cookieManager.set_config_value("appkey", appkey) | ||
payload = { | ||
"clientKey": appkey, | ||
"task": { | ||
"type": 'GeeTestTaskProxyLess', | ||
"websiteURL": referer, | ||
"gt": gt, | ||
"challenge": challenge, | ||
}} | ||
res = requests.post("https://api.capsolver.com/createTask", json=payload) | ||
resp = res.json() | ||
task_id = resp.get("taskId") | ||
if not task_id: | ||
raise ValueError("Failed to create task: " + res.text) | ||
loguru.logger.info(f"Got taskId: {task_id} / Getting result...") | ||
while True: | ||
time.sleep(1) | ||
payload = {"clientKey": appkey, "taskId": task_id} | ||
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload) | ||
resp = res.json() | ||
status = resp.get("status") | ||
if status == "ready": | ||
loguru.logger.info(resp.get("solution")) | ||
return resp.get("solution")['validate'] | ||
if status == "failed" or resp.get("errorId"): | ||
raise ValueError("Solve failed! response: " + res.text) | ||
if status == "processing": | ||
continue | ||
|
||
|
||
if __name__ == "__main__": | ||
# 使用示例 | ||
appkey = "xxxxxxxxxxxxxxxxxxx" | ||
_request = BiliRequest(cookies_config_path=cookies_config_path) | ||
test_res = _request.get( | ||
"https://passport.bilibili.com/x/passport-login/captcha?source=main_web" | ||
).json() | ||
challenge = test_res["data"]["geetest"]["challenge"] | ||
gt = test_res["data"]["geetest"]["gt"] | ||
loguru.logger.info(challenge) | ||
loguru.logger.info(gt) | ||
validator = CapSolverValidator() | ||
try: | ||
validate_string = validator.validate(appkey, gt, challenge) | ||
print(f"Validation String: {validate_string}") | ||
except Exception as e: | ||
print(f"Error: {e}") |
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,67 @@ | ||
from urllib import parse | ||
|
||
import loguru | ||
import requests | ||
from retry import retry | ||
|
||
from config import cookies_config_path, global_cookieManager | ||
from geetest.Validator import Validator | ||
from util.bili_request import BiliRequest | ||
from util.config_util import CookieManager | ||
|
||
|
||
class RROCRValidator(Validator): | ||
def __init__(self): | ||
self.url = "http://api.rrocr.com/api/recognize.html" | ||
self.headers = { | ||
"User-Agent": "Mozilla/5.0 Chrome/77.0.3865.120 Safari/537.36", | ||
"Accept": "text/html", | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
} | ||
self.cookieManager = global_cookieManager | ||
|
||
@retry() | ||
def validate(self, appkey, gt, challenge, referer="http://www.baidu.com", ip='', host='') -> str: | ||
if appkey is None or appkey == "": | ||
appkey = self.cookieManager.get_config_value("appkey", "") | ||
else: | ||
self.cookieManager.set_config_value("appkey", appkey) | ||
data = { | ||
"appkey": appkey, | ||
"gt": gt, | ||
"challenge": challenge, | ||
"referer": referer, | ||
"ip": ip, | ||
"host": host | ||
} | ||
data = parse.urlencode(data) | ||
response = requests.post(self.url, headers=self.headers, data=data) | ||
|
||
if response.status_code == 200: | ||
result = response.json() | ||
loguru.logger.info(result) | ||
if result.get("status") == 0: | ||
return result['data']['validate'] | ||
else: | ||
raise ValueError(f"识别失败: {result.get('msg')}") | ||
else: | ||
raise ConnectionError(f"Request failed with status code: {response.status_code}") | ||
|
||
|
||
if __name__ == "__main__": | ||
# 使用示例 | ||
appkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
_request = BiliRequest(cookies_config_path=cookies_config_path) | ||
test_res = _request.get( | ||
"https://passport.bilibili.com/x/passport-login/captcha?source=main_web" | ||
).json() | ||
challenge = test_res["data"]["geetest"]["challenge"] | ||
gt = test_res["data"]["geetest"]["gt"] | ||
loguru.logger.info(challenge) | ||
loguru.logger.info(gt) | ||
validator = RROCRValidator() | ||
try: | ||
validate_string = validator.validate(appkey, gt, challenge) | ||
print(f"Validation String: {validate_string}") | ||
except Exception as e: | ||
print(f"Error: {e}") |
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