add user-agent list

This commit is contained in:
2022-03-21 17:13:11 +01:00
parent 68680af13b
commit a5b172d4d6
3 changed files with 113 additions and 72 deletions
+97 -68
View File
@@ -1,15 +1,18 @@
import asyncio
import subprocess
import logging
import random
import threading
import time
from concurrent.futures import ProcessPoolExecutor
import playwright
from playwright.async_api import async_playwright
from playwright.sync_api import sync_playwright
from pojo.contact_pojo import ContactPojo
from utils.excel_reader import ExcelHelper
# RDV_URL = "https://rendezvousparis.hermes.com/client/register"
RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
RDV_URL = "https://rendezvousparis.hermes.com/client/register"
# RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
# RDV_URL = "https://www.google.fr"
@@ -17,57 +20,90 @@ RDV_URL = "file:///Users/lpan/Downloads/test_appointment.html"
# RDV_URL = "https://api.ipify.org"
global_page = None
otp_value = None
user_agent_list = ExcelHelper().read_user_agent_list()
class CommandorPage:
def __init__(self):
pass
async def start_page(self, proxy, contact: ContactPojo):
def _run(self, e: threading.Event, proxy, contact):
with sync_playwright() as pwright:
self.browser = pwright.chromium.launch(headless=False, timeout=90000, proxy=proxy)
self.page = self.browser.new_page(
user_agent=random.choice(user_agent_list))
global global_page
global_page = self
self.page.on("load", self.on_page_loaded)
self.page.goto(RDV_URL, timeout=90000)
# content = self.page.content()
self.setPhoneCountry()
self.setPhoneNumber(contact.phone)
self.setName(contact.last_name, contact.first_name)
self.setEmail(contact.mail)
self.setIdNumber(contact.passport)
self.checkCgu()
self.page.on("domcontentloaded", self.on_document_loaded)
self.clickOnValidBtn()
event_is_set = e.wait()
logging.debug('event set: %s', event_is_set)
global otp_value
self.send_otp(otp_value)
self.clickOnValidBtn()
self.page.on("load", self.on_page_loaded)
time.sleep(4000)
# time.sleep(1000)
def start_page(self, proxy, contact: ContactPojo) -> threading.Event:
# specifying an explicit component name
async with async_playwright() as pwright:
self.browser = await pwright.chromium.launch(headless=False, timeout=30000, proxy=proxy)
self.page = await self.browser.new_page(
user_agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Mobile Safari/537.36")
await self.page.goto(RDV_URL)
content = await self.page.content()
await self.setPhoneCountry()
await self.setPhoneNumber(contact.phone)
await self.setName(contact.last_name, contact.first_name)
await self.setEmail(contact.mail)
await self.setIdNumber(contact.passport)
await self.checkCgu()
await self.clickOnValidBtn()
# page.on('load', self.on_page_loaded)
print(content)
await asyncio.sleep(1000)
e = threading.Event()
t = threading.Thread(target=self._run, args=(e, proxy, contact))
t.start()
return e
def on_page_loaded(self):
print("page loaded")
print("content is " + self.page.content())
print("url is " + self.page.url)
self.getErrors()
async def setPhoneCountry(self):
await self.page.evaluate("""()=>document.getElementById("phone_country").value = \"FR\" """)
def on_response(self):
print("on_response called")
async def setPhoneNumber(self, phoneNumber):
await self.page.evaluate("""(phoneNumber)=>document.getElementById("phone_number").value =phoneNumber""",
def on_document_loaded(self):
print("on_document_loaded called")
def setPhoneCountry(self):
self.page.evaluate("""()=>document.getElementById("phone_country").value = \"FR\" """)
def setPhoneNumber(self, phoneNumber):
self.page.evaluate("""(phoneNumber)=>document.getElementById("phone_number").value =phoneNumber""",
phoneNumber)
async def setName(self, lastName, firstName):
await self.page.evaluate("""(name)=> {
def setName(self, lastName, firstName):
self.page.evaluate("""(name)=> {
document.getElementById("surname").value = name.lastName;
document.getElementById("name").value = name.firstName}""", {'lastName': lastName, 'firstName': firstName})
async def setEmail(self, email):
await self.page.evaluate("""(email)=>document.getElementById("email").value = email""", email)
def getErrors(self):
items = self.page.query_selector(".alert")
if items:
print(items.inner_html())
async def setIdNumber(self, id):
await self.page.evaluate(""" (id) => document.getElementById("passport_id").value = id""", id)
def setEmail(self, email):
self.page.evaluate("""(email)=>document.getElementById("email").value = email""", email)
async def checkCgu(self):
await self.page.evaluate("""document.getElementById("cgu").checked = true;
def setIdNumber(self, id):
self.page.evaluate(""" (id) => document.getElementById("passport_id").value = id""", id)
def checkCgu(self):
self.page.evaluate("""document.getElementById("cgu").checked = true;
document.getElementById("processing").checked = true""")
async def clickOnValidBtn(self):
await self.page.evaluate("""document.getElementsByClassName("btn")[0].click();""")
def clickOnValidBtn(self):
self.page.evaluate("""document.getElementsByClassName("btn")[0].click();""")
def clear_app_data(self):
pass
@@ -76,44 +112,37 @@ class CommandorPage:
self.page.evaluate("""(otp)=> document.getElementById("sms_code").value = otp""", otp)
def reset_air_plan_mode(self):
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 1",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell settings put global airplane_mode_on 0",
shell=True)
time.sleep(1)
subprocess.call(
"/Users/panlei/Library/Android/sdk/platform-tools/adb shell am broadcast -a android.intent.action.AIRPLANE_MODE",
shell=True)
time.sleep(10)
pass
async def main():
contact = ContactPojo(phone_number="755667750", passport_number="5123456789", last_name="PAN", first_name="Lei",
mail="panleicim@gmail.com", ccid="", position=0)
def main():
executor = ProcessPoolExecutor(2)
loop = asyncio.get_event_loop()
loop.run_in_executor(executor, wait_for_otp)
loop.run_in_executor(executor, launch_page)
def launch_page() -> threading.Event:
proxy = {
"server": "http://gw.ntnt.io:5959",
"username": "panleicim-cc-fr-sid-179112",
"password": "M3PZAXgW5V27"
}
contact = ContactPojo(phone_number="+33751177505", passport_number="9933251119", last_name="Chen", first_name="Fan",
mail="lei_chena09@outlook.com", ccid="", position=0)
page = CommandorPage()
await page.start_page(None, contact)
# task = asyncio.create_task(wait_for_otp())
# await task
return page.start_page(proxy, contact)
async def wait_for_otp():
sec = input("Press Enter to continue...")
time.sleep(20)
def wait_for_otp():
sec = input("Press Enter otp to continue...")
asyncio.sleep(1)
print("input otp is: " + sec)
if __name__ == '__main__':
proxy = {
"server": "http://gw.ntnt.io:5959",
"username": "panleicim-cc-any-sid-1112",
"password": "M3PZAXgW5V27"
}
asyncio.gather(main(), wait_for_otp())
time.sleep(1000)
event = launch_page()
sec = input("Press Enter otp to continue...")
print("input otp is: " + sec)
otp_value = sec
event.set()
Binary file not shown.
+13 -1
View File
@@ -2,6 +2,7 @@ import json
import pandas as pandas
import definitions
from pojo.contact_pojo import ContactPojo
@@ -24,7 +25,17 @@ class ExcelHelper:
self.write_to_exel("ccid_list.xlsx", ccids.split(","))
print(lines)
def read_user_agent_list(self):
# read the contact list from the exel file
contact_list_in_json = pandas.read_excel(definitions.ROOT_DIR + "/docs/mobile_user_agent_list.xlsx").to_json(
orient='records')
contact_dict_list = json.loads(contact_list_in_json)
user_agents = []
for contact_dict in contact_dict_list:
user_agent = contact_dict['user_agent']
user_agents.append(user_agent)
return user_agents
def read_contacts(self) -> list:
contact_list_in_json = pandas.read_excel(r'./contact.xlsx').to_json(orient='records')
contact_dict_list = json.loads(contact_list_in_json)
@@ -46,4 +57,5 @@ class ExcelHelper:
if __name__ == '__main__':
helper = ExcelHelper()
helper.generate_exel_from_txt()
# helper.generate_exel_from_txt()
print(helper.read_user_agent_list())