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()
    
# 浏览器操作
    
相关推荐
Leuanghing13 分钟前
【Leetcode】11. 盛最多水的容器
python·算法·leetcode
xinxiyinhe1 小时前
如何设置Cursor中.cursorrules文件
人工智能·python
诸神缄默不语2 小时前
如何用Python 3自动打开exe程序
python·os·subprocess·python 3
看,未来2 小时前
Apipost 与 Postman 工具实践指南:WebSocket调试与动态参数测试
websocket·测试工具·postman
橘子师兄2 小时前
分页功能组件开发
数据库·python·django
shimly1234562 小时前
tcpdump 用法示例
网络·测试工具·tcpdump
Logintern093 小时前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
Multiple-ji3 小时前
想学python进来看看把
开发语言·python
liuyuzhongcc3 小时前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list
程序员老舅3 小时前
C++ Qt项目教程:WebServer网络测试工具
c++·qt·测试工具·webserver·qt项目·qt项目实战