test 2captcha
This commit is contained in:
@@ -6,6 +6,7 @@ import threading
|
||||
import time
|
||||
from typing import Union
|
||||
|
||||
import requests
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
import params
|
||||
@@ -19,6 +20,8 @@ RDV_URL = "https://rendezvousparis.hermes.com/client/register"
|
||||
# RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
|
||||
# RDV_URL = "https://api.ipify.org"
|
||||
# RDV_URL ="https://bot.sannysoft.com/"
|
||||
REGEX_DATA_SITE_KEY = "data-sitekey=[\"a-z0-9A-Z]+"
|
||||
CAPCHA_NOT_READY = "CAPCHA_NOT_READY"
|
||||
REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
||||
otp_value = None
|
||||
OTP_FIELD_ID = "#sms_code"
|
||||
@@ -92,6 +95,8 @@ class CommandorPage:
|
||||
"password": params.PROXY_PASSWORD
|
||||
}
|
||||
self.fill_fields()
|
||||
# wait the captha element
|
||||
self.find_data_sitekey()
|
||||
# wait for sms_code field
|
||||
# self.clickOnValidBtn()
|
||||
self.thread_event = e
|
||||
@@ -288,7 +293,6 @@ class CommandorPage:
|
||||
def clear_app_data(self):
|
||||
pass
|
||||
|
||||
|
||||
def click_recapcha_checkbox(self):
|
||||
captcha_solver = SolveCaptcha(self.page)
|
||||
captcha_solver.start()
|
||||
@@ -319,6 +323,43 @@ class CommandorPage:
|
||||
time.sleep(2)
|
||||
self.browser.close()
|
||||
|
||||
def find_data_sitekey(self):
|
||||
content = self.page.content()
|
||||
data_sitekey = re.findall(REGEX_DATA_SITE_KEY, content)
|
||||
self.logger.info(data_sitekey)
|
||||
if len(data_sitekey) == 1:
|
||||
key_with_comma = data_sitekey[0].split("=")[-1]
|
||||
key = key_with_comma.replace("\"", '')
|
||||
print("key is : " + key)
|
||||
self.send_to_resolve_captcha(key)
|
||||
|
||||
def send_to_resolve_captcha(self, google_key: str):
|
||||
url_get = "http://2captcha.com/in.php?key=e7e3cd0977aba2dab49e0ea052ca58b1&method=userrecaptcha&googlekey={}&pageurl={}".format(
|
||||
google_key, self.page.url)
|
||||
res = requests.get(url_get)
|
||||
print(res.text)
|
||||
results = res.text.split("|")
|
||||
self.captcha_id = results[-1]
|
||||
# wait for 15 seconds
|
||||
time.sleep(15)
|
||||
# get result of the captcha
|
||||
url_response = "http://2captcha.com/res.php?key=e7e3cd0977aba2dab49e0ea052ca58b1&action=get&id={}".format(
|
||||
self.captcha_id)
|
||||
solution = CAPCHA_NOT_READY
|
||||
while solution == CAPCHA_NOT_READY:
|
||||
solution_res = requests.get(url_response)
|
||||
print(solution_res.text)
|
||||
solution = solution_res.text
|
||||
print(solution)
|
||||
self.fill_captcha_solution(solution.split("|")[-1])
|
||||
|
||||
def fill_captcha_solution(self, solution):
|
||||
self.logger.info("wil input solution: " + solution)
|
||||
self.page.evaluate("""(solution)=>{
|
||||
let captcha_response = document.getElementById("g-recaptcha-response");
|
||||
captcha_response.innerHTML=solution;}}""", solution)
|
||||
self.clickOnValidBtn()
|
||||
|
||||
|
||||
def get_random_id_number() -> str:
|
||||
S = 8 # number of characters in the string.
|
||||
|
||||
Reference in New Issue
Block a user