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()
    
# 浏览器操作
    
相关推荐
平常心cyk16 分钟前
Python基础快速复习——函数的多种传参方式
python
lanboAI22 分钟前
基于卷积神经网络的舌苔诊断系统,resnet50,alexnet, shufflenet模型【pytorch框架+python源码】
pytorch·python·cnn
QWsin31 分钟前
【Pydantic】Pydantic 是什么?
python
WeeJot嵌入式31 分钟前
爬虫对抗:ZLibrary反爬机制实战分析
爬虫·python·网络安全·playwright·反爬机制
Bert.Cai44 分钟前
Python input函数作用
开发语言·python
Fairy要carry1 小时前
项目03-手搓Agent之团队协作(发消息/分配任务)
linux·前端·python
柚子+1 小时前
Appium+python+雷电模拟器自动化测试入门
数据库·python·appium
rgb2gray1 小时前
论文详解:基于POI与出租车轨迹的城市多中心结构静态-动态多重分形特征
人工智能·python·算法·机器学习·数据分析·可解释
github_czy1 小时前
Python 函数式编程利器:Partial 与 ParamSpec 技术解析
python·fastapi
IT小哥哥呀1 小时前
实战!【一个企业知识库的逐步搭建】持续更新ing
python·ai·大模型·知识库·chunk·向量搜索·weknora