java vm启动_JAVA 使用VMLogin自动化API接口启动浏览器代码

本文介绍了一种使用VMLogin启动带有特定配置文件的Chrome浏览器实例的方法,并通过Selenium进行自动化操作。具体步骤包括启动配置文件以获取调试地址,然后利用该地址通过Selenium的ChromeOptions设置来连接已打开的Chrome浏览器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.ruoyi.common.spider.reptile;

import cn.hutool.json.JSONObject;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

/**

* @author vmlogin

*         

*             org.seleniumhq.selenium

*             selenium-java

*             3.141.59

*         

*/

public class ProductChrome {

public static void main(String[] args) throws Exception {

ProductChrome pc = new ProductChrome();

String profileId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

//根据profileId打开并获取远程调试地址

URL url = new URL(pc.startProfile(profileId));

//使用远程调试地址连接到打开的chrome浏览器

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.setExperimentalOption("debuggerAddress", url.getAuthority());

WebDriver driver = new ChromeDriver(chromeOptions);

//访问vmlogin

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

System.out.println(driver.getTitle());

driver.quit();

}

private String startProfile(String profileId) throws Exception {

String url = "http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId=" + profileId;

URL obj = new URL(url);

HttpURLConnection con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod("GET");

BufferedReader in = new BufferedReader(

new InputStreamReader(con.getInputStream()));

String inputLine;

StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {

response.append(inputLine);

}

in.close();

JSONObject jsonResponse = new JSONObject(response.toString());

return jsonResponse.getStr("value");

}

}

VMLogin反指纹防关联超级浏览器:https://www.vmlogin.org/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值