云登浏览器 + (puppeteer、selenium)+ ( js + python) 调试

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

id:环境管理 > 环境列表 > 序号/ID

在这里插入图片描述

api 启动环境

http://localhost:50213/api/v2/browser/start?account_id=环境id

返回数据

{
    "code": 0,
    "msg": "success",
    "data": {
        "ws": {
            "selenium": "127.0.0.1:52412",
            "puppeteer": "ws://127.0.0.1:52412/devtools/browser/*****************"
        },
        "debuggingPort": "52412",
        "webdriver": "C:\\Users\\oowwe\\FbBrowser\\3.0.0.5\\chromedriver.exe"
    }
}

puppeteer

“puppeteer”: “18.2.1” 测试正常

// 环境id
fetch(`http://localhost:50213/api/v2/browser/start?account_id=${id}`)
    .then((response) => response.json())
    .then((res) => {
      createPage(res.data.ws.puppeteer);
    })
    .catch((err) => {
      // console.log('连接店铺失败失败', err);
    });
    
const createPage = async (ws: string) => {
    rpaController.browser = await puppeteer.connect({
      browserWSEndpoint: ws,
    });
    
    // 监听连接断开事件
    rpaController.browser.on('disconnected', wsDisconnected);
  };

selenium

客户使用selenium+webdriver控制浏览器,版本兼容问题增加命令行参数:“–disable-build-check” 即可:例如: service = webdriver.ChromeService.Service(service_args=[‘–disable-build-check’], executable_path=chromedriver_path)

js

npm init

npm install selenium-webdriver

npm i axios

main.js

const { Builder, By, until } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const axios = require("axios");

/**
 * 启动子浏览器
 * @param {string} browserid 环境id
 */
async function start(browserid) {
  var res = await axios.get(
    `http://127.0.0.1:50213/api/v2/browser/start?account_id=${browserid}`
  );

  const { code, data } = res.data;

  if (code === 0) {
    const service = new chrome.ServiceBuilder(data.webdriver)
    const options = new chrome.Options();

    service.addArguments('--disable-build-check')
    options.setChromeBinaryPath(data.webdriver)
    options.addArguments(`--remote-debugging-port=${data.debuggingPort}`); // 远程调试端口
    options.debuggerAddress(data.ws.selenium)

    const driver = new Builder()
      .forBrowser("chrome")
      .setChromeOptions(options)
      .setChromeService(service)
      .build();

    await driver.get("https://www.yunlogin.com/");

    driver.findElement(By.xpath("//nav/ul/li[5]")).click();

    driver.wait(
      until.titleIs("指纹浏览器下载-防关联浏览器多开-电商浏览器-Yunlogin"),
      10000
    );
  }
}

start("152829437d878d7a0e************");


python

# -*- coding:utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import requests


def driver_setting_yundeng(browserid):
    # time.sleep(2)

    headers = {
        'Content-Type': 'application/json'
    }
    url = f"http://localhost:50213/api/v2/browser/start?account_id={browserid}"
    response = requests.get(url, headers=headers)
    json_data = response.json()
    print('获取店铺信息', json_data)
    print('driver开始配置', int(time.time()))

    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_experimental_option("debuggerAddress", json_data['data']['ws']['selenium'])
    
    # 指定chromedriver的路径
    # chromedriver_path = json_data['data']['webdriver']
    # service = Service(executable_path=chromedriver_path)
    chromedriver_path = json_data['data']['webdriver']
    service = Service(service_args=['--disable-build-check'], executable_path=chromedriver_path)

    driver = webdriver.Chrome(options=options, service=service)
    return driver

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值