本文使用WebDriver进行代理实现自动登陆,实测可用。
1、unity中放入Packages包,文件包在代码包里
2、找到自己Edge浏览器对应的版本,下载对应的msedgedriver.exe
https://learn.microsoft.com/zh-cn/microsoft-edge/webdriver-chromium/?tabs=c-sharp
3、将下载的msedgedriver.exe放在E盘下
4、Unity中脚本(打开网页看Html网页对应的用户名、密码和登陆Button是什么属性)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
public Button btn1;
void Start()
{
btn1.onClick.AddListener(OpenPage);
}
private static void OpenPage()
{
// 创建 EdgeOptions 对象,设置 Edge 浏览器的路径和启动参数
EdgeOptions options = new EdgeOptions();
options.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
options.AddArgument("start-maximized");
// 创建 EdgeDriver 对象,传入 EdgeOptions 对象
// 指定 Microsoft Edge WebDriver 的路径
string driverPath = @"E:\";
// 创建 EdgeDriver 对象,传入 EdgeOptions 对象和 WebDriver 路径
IWebDriver driver = new EdgeDriver(driverPath, options);
// 导航到登录页面
driver.Navigate().GoToUrl("https://db.zjrd.gov.cn/#/login");
// 输入用户名和密码
IWebElement usernameInput = driver.FindElement(By.Name("username"));
usernameInput.SendKeys("");
IWebElement passwordInput = driver.FindElement(By.Name("password"));
passwordInput.SendKeys("");
// 找到登录按钮并点击
IWebElement loginButton = driver.FindElement(By.CssSelector("button[data-v-a09fc712]"));
loginButton.Click();
// 关闭浏览器
//driver.Quit();
}
}