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.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