-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_whatsapp_firefox_init.py
executable file
·63 lines (47 loc) · 2.05 KB
/
bot_whatsapp_firefox_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
# secure imports
import configparser
from config.data import USER_DATA_PATH, SESSION_PATH
def create_driver_session(session_id, executor_url):
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
# Save the original function, so we can revert our patch
org_command_execute = RemoteWebDriver.execute
def new_command_execute(self, command, params=None):
if command == "newSession":
# Mock the response
return {'success': 0, 'value': None, 'sessionId': session_id}
else:
return org_command_execute(self, command, params)
# Patch the function before creating the driver object
RemoteWebDriver.execute = new_command_execute
new_driver = webdriver.Remote(command_executor=executor_url, desired_capabilities={})
new_driver.session_id = session_id
# Replace the patched function with original function
RemoteWebDriver.execute = org_command_execute
return new_driver
base_url = 'https://web.whatsapp.com/'
timeout = 5#30
options = webdriver.FirefoxOptions()
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument("--disable-plugins-discovery")
options.add_argument("--user-data-dir=%s"%SESSION_PATH) # setear ruta local path
browser = webdriver.Firefox(firefox_options=options)
browser.get(base_url)
session_id = browser.session_id
executor_url = browser.command_executor._url
config = configparser.ConfigParser()
config.read("config/session/session.ini")
config['SESSION']['session_id'] = session_id
config['SESSION']['executor_url'] = executor_url
with open('config/session/session.ini', 'w') as configfile:
config.write(configfile)
input() # scan the qr
browser.close()