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()
    
# 浏览器操作
    
相关推荐
vibag5 分钟前
FastAPI框架
python·pycharm·fastapi
站大爷IP15 分钟前
从零开始用Python生成码:自定义样式与Logo嵌入
python
天才测试猿37 分钟前
2026全新软件测试面试八股文【含答案+文档】
自动化测试·软件测试·python·功能测试·测试工具·面试·职场和发展
TonyLee01739 分钟前
python深拷贝与浅拷贝机制
python
用户8356290780511 小时前
如何将 Python 列表高效导出为 Excel 文件
后端·python
安娜的信息安全说1 小时前
LangGraph:构建智能工作流的新方式
python·ai·langgraph
爱吃泡芙的小白白2 小时前
如何在现有配置好环境的Pycharm中安装jupyterlab这个工具
ide·python·pycharm·notebook·虚拟环境·jupyterlab
六毛的毛2 小时前
比较含退格的字符串
开发语言·python·leetcode
小鸡吃米…2 小时前
机器学习 - Python 库
人工智能·python·机器学习
xingzhemengyou12 小时前
Python GUI之tkinter-基础控件
开发语言·python