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()
    
# 浏览器操作
    
相关推荐
badhope5 分钟前
GitHub热门AI技能Top20实战指南
前端·javascript·人工智能·git·python·github·电脑
前端付豪15 分钟前
练习单导出
前端·python·llm
@OuYang18 分钟前
android10 应用安装
开发语言·python
_MyFavorite_22 分钟前
Python 中通过命令行向函数传参
开发语言·chrome·python
墨染天姬22 分钟前
【AI】TensorFlow 框架
人工智能·python·tensorflow
jianfeng_zhu33 分钟前
用java解决空心金字塔的问题
java·开发语言·python
乘风破浪的小太阳1 小时前
Python之Playwright+AI UI自动化测试框架搭建与实战
人工智能·python·ui
chushiyunen1 小时前
pycharm打包whl
人工智能·pytorch·python
墨染天姬1 小时前
【AI】PyTorch 框架
人工智能·pytorch·python
AI+程序员在路上1 小时前
在pyCharm 中命令打包生成exe文件方法
ide·python·pycharm