当前位置: 首页 > article >正文

selenium连接远程chrome浏览器

连接本地浏览器

  1. 命令行启动浏览器

    chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenium\ChromeProfile"
    
  2. selenium连接

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.debugger_address = "127.0.0.1:9222"
    service = webdriver.ChromeService(
        executable_path=r'C:\Users\Administrator\.cache\selenium\chromedriver\win64\128.0.6613.84\chromedriver.exe')
    driver = webdriver.Chrome(service=service, options=options)
    driver.get("https://www.baidu.com")
    # 其他操作
    

连接远程浏览器

  1. 在远程机器命令行启动浏览器

    chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenium\ChromeProfile"
    
  2. 在远程机器安装socat-windows,使用9223端口代理本地9222端口

    • 下载地址:https://github.com/StudioEtrange/socat-windows

    • 启动代理

      socat.exe TCP-LISTEN:9223,fork TCP:localhost:9222
      
  3. 本地selenium连接

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.debugger_address = "192.168.100.12:9223"
    service = webdriver.ChromeService(
        executable_path=r'C:\Users\Administrator\.cache\selenium\chromedriver\win64\128.0.6613.84\chromedriver.exe')
    driver = webdriver.Chrome(service=service, options=options)
    driver.get("https://www.baidu.com")
    # 其他操作
    

使用selenium-grid

  1. 下载jar包

    • 下载地址:https://github.com/SeleniumHQ/selenium/releases
    • 参考文档:https://www.selenium.dev/zh-cn/documentation/grid/getting_started/
  2. 命令行启动

    java -jar selenium-server-4.23.0.jar standalone --username test --password 123456 --port 8899 --max-sessions 2 --session-timeout 30
    
  3. 启动远程浏览器测试

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    driver = webdriver.Remote('http://test:123456@192.168.100.156:8899', options=options)
    driver.maximize_window()
    # 需要关闭浏览器
    driver.quit()
    

使用chrome-proxy

  1. 安装: pip install chrome-proxy -U

  2. 命令行启动代理服务器:chrome_proxy

  3. 本地selenium连接

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.debugger_address = "192.168.100.12:9223"
    service = webdriver.ChromeService(
        executable_path=r'C:\Users\Administrator\.cache\selenium\chromedriver\win64\128.0.6613.84\chromedriver.exe')
    driver = webdriver.Chrome(service=service, options=options)
    driver.get("https://www.baidu.com")
    # 其他操作
    

http://www.kler.cn/news/292510.html

相关文章:

  • MIT线性代数
  • 【java】将Map的value类型定义为Object
  • 第十五题:三数之和
  • rancher搭建k8s及jenkins自动化部署
  • 骨传导耳机哪款好?精选五款热门骨传导耳机分享让你避免踩雷
  • 对HashMap的理解
  • 使用本地预训练模型可视化卷积每一部分
  • 基于自适应多变量超扭转的 Lyapunov 重新设计 RLV 姿态控制
  • Facebook与区块链:构建更安全的社交网络生态
  • MFC dll无法显示tooltip问题
  • Java-数据结构-链表-习题(三)(๑´ㅂ`๑)
  • java开发简历详解
  • Dubbo缓存
  • HTML 基础知识详解与代码示例
  • C++笔记16•数据结构:关联式容器map和set•
  • Java健康养老智慧相伴养老护理小程序系统源码代办陪诊陪护更安心
  • 阿里云身份证二要素详细使用
  • 第T2周:彩色图片分类
  • 828华为云征文|基于华为云Flexus云服务器X搭建jumpserver堡垒机软件
  • 电子病历、开药发药、住院检查、会员管理,SaaS模式B/S架构的云医院管理系统源码,云计算技术的医疗信息化解决方案
  • 经验笔记:Feeds流设计与实现
  • SpringMVC 第一次复学笔记
  • 解决 EasyExcel BigDecimal 加%的问题
  • 请解释Java Web中的Filter的作用和使用场景。什么是Java Web中的JSP?请解释其与Servlet的关系及各自优势。
  • OPC DA
  • 2024数学建模国赛高教社杯C题:农作物的种植策略 思路代码文章助攻手把手保姆级
  • 编程秘密武器:提升工作效率的关键工具
  • 图像增强及运算篇之顶帽运算和底帽运算
  • Databend 产品月报(2024年8月)
  • 智能电源控制箱