-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselenium_connect.py
More file actions
57 lines (45 loc) · 1.62 KB
/
selenium_connect.py
File metadata and controls
57 lines (45 loc) · 1.62 KB
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
"""
Selenium attach example (requires selenium + chromedriver compatible with Mimic).
pip install selenium
set MULTILOGIN_PROFILE_ID=...
python selenium_connect.py
"""
import os
import sys
import time
from load_env import bootstrap_env
from multilogin_client import MultiloginClient, MultiloginError
bootstrap_env()
def main() -> None:
profile_id = os.environ.get("MULTILOGIN_PROFILE_ID", "")
if not profile_id:
print("Set MULTILOGIN_PROFILE_ID", file=sys.stderr)
sys.exit(1)
try:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
except ImportError:
print("pip install selenium", file=sys.stderr)
sys.exit(1)
with MultiloginClient() as client:
try:
with client.profile(profile_id) as session:
addr = session.selenium_address
if not addr:
print("No debug port in start response. Set options manually.")
print("Response:", session.response)
sys.exit(1)
options = Options()
options.add_experimental_option("debuggerAddress", addr)
print(f"Connecting Selenium to {addr}...")
driver = webdriver.Chrome(options=options)
driver.get("https://browserleaks.com/javascript")
print("Title:", driver.title)
time.sleep(3)
driver.quit()
except MultiloginError as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
print("Done.")
if __name__ == "__main__":
main()