selenium 9222

直接连接9222 会等待很长时间,多线程尝试连接9222,join(timeout=2),结果放brower。

如果brower是空,os执行 chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile" ,然后在主线程再次连接9222

python 复制代码
import os

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from threading import Thread

# 直接连接9222 会等待很长时间
# 多线程尝试连接9222,join(timeout=2)
# if brower ='',
# os执行 chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"
# 再次连接9222

brower = ''
chrome_options = Options()
chrome_options.add_experimental_option('debuggerAddress', "127.0.0.1:9222")


def connect():
    global brower
    brower = webdriver.Chrome(executable_path="???",
                              chrome_options=chrome_options)


t = Thread(target=connect)
t.start()
t.join(2)
if brower == '':
    os.system('chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"')
    connect()
    
# 浏览器操作
    
相关推荐
qq_417695054 小时前
机器学习与人工智能
jvm·数据库·python
漫随流水4 小时前
旅游推荐系统(view.py)
前端·数据库·python·旅游
yy我不解释5 小时前
关于comfyui的mmaudio音频生成插件时时间不一致问题(一)
python·ai作画·音视频·comfyui
紫丁香6 小时前
AutoGen详解一
后端·python·flask
FreakStudio6 小时前
不用费劲编译ulab了!纯Mpy矩阵micronumpy库,单片机直接跑
python·嵌入式·边缘计算·电子diy
清水白石0088 小时前
Free-Threaded Python 实战指南:机遇、风险与 PoC 验证方案
java·python·算法
为你奋斗!9 小时前
图形化界面工具 - webUI使用Page Assist 插件
测试工具
飞Link9 小时前
具身智能核心架构之 Python 行为树 (py_trees) 深度剖析与实战
开发语言·人工智能·python·架构
CN.LG9 小时前
抓包工具 Wireshark 是什么?
网络·测试工具·wireshark
桃气媛媛9 小时前
Pycharm常用快捷键
python·pycharm