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()
    
# 浏览器操作
    
相关推荐
闲人编程25 分钟前
构建一个基于Flask的URL书签管理工具
后端·python·flask·url·codecapsule·书签管理
song85460113431 分钟前
锁的初步学习
开发语言·python·学习
Dcs44 分钟前
提升 Python 性能的 10 个智能技巧
python
深蓝电商API1 小时前
0 基础入门爬虫:Python+requests 环境搭建保姆级教程
开发语言·爬虫·python
MediaTea2 小时前
Python 第三方库:PyTorch(动态计算图的深度学习框架)
开发语言·人工智能·pytorch·python·深度学习
kyle-fang2 小时前
pytorch-张量转换
人工智能·pytorch·python
Blossom.1182 小时前
AI Agent记忆系统深度实现:从短期记忆到长期人格的演进
人工智能·python·深度学习·算法·决策树·机器学习·copilot
yanxiaoyu1102 小时前
Pycharm远程调用Autodl进行训练(关机后不影响)
ide·python·pycharm
云和数据.ChenGuang2 小时前
Python 3.14 与 PyCharm 2025.2.1 的调试器(PyDev)存在兼容性问题
开发语言·python·pycharm
mortimer2 小时前
从零打造一款桌面实时语音转文字工具:PySide6 与 Sherpa-Onnx 的实践
python·github·pyqt