add mobile proxy to GUI

This commit is contained in:
2022-09-02 15:46:45 +02:00
parent 7af4eed43c
commit 75c1290a08
6 changed files with 50 additions and 247 deletions
+30 -28
View File
@@ -2,6 +2,8 @@ import datetime
import logging
import random
import re
import requests
import sys
import threading
import time
@@ -23,6 +25,8 @@ RDV_URL = "https://rendezvousparis.hermes.com/client/register"
# RDV_URL = "https://api.ipify.org"
# RDV_URL ="https://bot.sannysoft.com/"
REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
BLOCKED_MESSAGE_FR = "Pourquoi ce blocage"
BLOCKED_MESSAGE_EN = "You have been blocked"
otp_value = None
OTP_FIELD_ID = "#sms_code"
MESSAGE_FIELD_CLASS = ".message"
@@ -49,7 +53,7 @@ def get_random_wait_time() -> float:
class CommandorPage:
tls = TlsPlaywright()
def __init__(self, contact: ContactPojo, store_type=0, proxy_type=ProxyType.BRIGHT_DATA,
def __init__(self, contact: ContactPojo, store_type=0, proxy_type=ProxyType.RESIDENTIAL,
mode: ModeEnum = ModeEnum.MANUAL, headless=False):
self.otp_value = None
self.is_finished = False
@@ -92,6 +96,12 @@ class CommandorPage:
self.on_success_listener = on_success
# reset otp_value to None
self.otp_value = None
# ios_devices_keys = self.tls.playwright.devices.keys()
# ios_keys = []
# for key in ios_devices_keys:
# if "iPhone" in key or "iPad" in key:
# ios_keys.append(key)
# print(ios_keys)
devices = random.choice(params.DEVICES)
first_page = None
while first_page is None:
@@ -125,7 +135,7 @@ class CommandorPage:
userAgent = simulated_mobile['user_agent']
print("user_agent is " + userAgent)
context = self.browser.new_context(**simulated_mobile, locale='fr-FR')
#context = self.browser.new_context(user_agent=userAgent, locale='fr-FR')
# context = self.browser.new_context(user_agent=userAgent, locale='fr-FR')
self.page = context.new_page()
# hide webdriver information
self.page.add_init_script("""() => {
@@ -140,30 +150,6 @@ class CommandorPage:
self.page.on("response", self.handle_response)
self.page.goto(RDV_URL, timeout=PAGE_TIMEOUT)
return self.page.content()
# self.browser = pwright.webkit.launch(headless=self.headless, timeout=PAGE_TIMEOUT, proxy=proxy)
# self.logger.info("模拟设备: " + device)
# simulated_mobile = pwright.devices[device]
# context = self.browser.new_context(**simulated_mobile, locale='fr-FR')
# self.page = context.new_page()
# # hide webdriver information
# self.page.add_init_script("""() => {
# Object.defineProperty(navigator,'webdriver',{get: () => undefined});
# Object.defineProperty(navigator, 'platform', {
# get: () => {
# return "iPhone";
# }});
# }
# """)
# self.page.on("load", self._on_page_loaded)
# self.page.on("response", self.handle_response)
# self.page.goto(RDV_URL, timeout=PAGE_TIMEOUT)
# captcha_url = "geo.captcha-delivery.com/captcha"
# if captcha_url in self.page.content():
# self.logger.info("will close browser")
# self.browser.close()
# return None
# else:
# return self.page.content()
except Exception as error:
params.oracle_log_sender.send_error(str(error))
traceback.print_exc(*sys.exc_info())
@@ -179,7 +165,6 @@ class CommandorPage:
# self.publish_message_to_queue(self.contact, PublishType.PENDING, response.url)
def start_page(self, proxy):
e = threading.Event()
self._run(proxy)
def _on_page_loaded(self):
@@ -198,6 +183,10 @@ class CommandorPage:
self.get_errors()
except Exception as error:
self.logger.error(error)
else:
if self.check_is_blocked():
print("we are blocked")
# self.termine()
def on_document_loaded(self):
self.logger.info("on_document_loaded called")
@@ -377,6 +366,19 @@ class CommandorPage:
MONGO_STORE_MANAGER.insert_captcha_error_contact(self.contact)
params.oracle_log_sender.send_captcha_error(self.contact)
def check_is_blocked(self) -> bool:
iframe = self.page.query_selector('iframe').content_frame()
self.iframe = iframe
print(type(iframe))
print("url is " + iframe.url)
r = requests.get(iframe.url)
body = r.text
# print("iframe content is " + body)
if BLOCKED_MESSAGE_FR in body or BLOCKED_MESSAGE_EN in body:
return True
else:
return False
def on_success(result: ReserveResultPojo):
pass
@@ -387,7 +389,7 @@ def launch_page():
first_name="xingzhen",
mail="ColbyPatel653@gmail.com", ccid="", position=0)
page = CommandorPage(contact, store_type=1)
return page.start_page(params.get_proxy(ProxyType.BRIGHT_DATA))
return page.start_page(params.get_proxy(ProxyType.RESIDENTIAL))
def wait_for_otp(event: threading.Event, commandor: CommandorPage):
+1 -1
View File
@@ -23,7 +23,7 @@ DOUBLE_REQUEST_ERROR_MESSAGE_FR = "Une demande avec les données saisies a déj
class LinkValidator:
tls = TlsPlaywright()
def __init__(self, link: str, proxy_type=ProxyType.BRIGHT_DATA, headless=False):
def __init__(self, link: str, proxy_type=ProxyType.RESIDENTIAL, headless=False):
self.is_finished = False
self.link = link
self.proxy_type = proxy_type