1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| ChromeOptions options = new ChromeOptions();
bool ifShowBrowser = this._ConfigItem.ifShowBrowser; if (!ifShowBrowser) options.AddArgument("-headless");
options.AddArgument("--window-size=1920,1050");
options.AddArgument("log-level=3");
options.AddArgument("--disable-blink-features=AutomationControlled"); options.AddArgument("--disable-blink-features=AutomationControlledCrOS");
options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.111 Safari/537.36");
options.AddArgument("--disable-webgl"); options.AddArgument("--disable-extensions"); options.AddArgument("--disable-plugins");
ChromeDriverService service = ChromeDriverService.CreateDefaultService(System.AppDomain.CurrentDomain.BaseDirectory.ToString()); service.HideCommandPromptWindow = !ifShowBrowser; ChromeDriver driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("http://cdcs.qgil.net/index"); Thread.Sleep(2000); if (driver.Url != "http://cdcs.qgil.net/index") { driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15); driver.FindElement(By.TagName("input")).SendKeys(this._ConfigItem.QG_Account); driver.FindElement(By.XPath("//*[@id=\"app\"]/div[1]/form/div[2]/div/div/input")).SendKeys(this._ConfigItem.QG_Password); driver.FindElement(By.XPath("//*[@id=\"app\"]/div[1]/form/div[4]/div[1]/div/div/button")).Click(); Actions tuozhuai = new Actions(driver); Thread.Sleep(1000); var huakuai = driver.FindElement(By.XPath("//*[@id=\"app\"]/div[1]/form/div[3]/div/div[2]/div/div[2]/div/div/div/images")).GetAttribute("src").Replace("data:image/png;base64,", ""); var beijing = driver.FindElement(By.XPath("//*[@id=\"app\"]/div[1]/form/div[3]/div/div[2]/div/div[1]/div/images")).GetAttribute("src").Replace("data:image/png;base64,", ""); #region 图片切割,因为背景图片上好多的凹槽块,云码识别大部分会识别失败,为了提高识别率只切割出来滑块对应的那一条背景进行识别 int offsetY = getHeight(huakuai, "\\UploadFile\\CDQG\\"); beijing = ImgHelper.CapturelmageByBase64(beijing, 0, offsetY - 1, offsetY + ".png", 310, 49, "\\UploadFile\\CDQG\\"); #endregion var dic = new Dictionary<string, string>() { { "token","Ax7TSY8X"}, { "slide_image",huakuai}, { "background_image",beijing}, { "type","20111"} }; var response = Post_customApi("https://www.jfbym.com/api/YmServer/customApi", dic, new Dictionary<string, string>()); var huakuaidiv = driver.FindElement(By.ClassName("verify-move-block")); Regex xs = new Regex("\"data\":\"[0-9]+\""); if (!string.IsNullOrEmpty(response)) { var result = xs.Match(response); if (result.Success) { var yidongjuli = result.Groups[0].ToString().Split(':')[1].Replace("\"", ""); tuozhuai.DragAndDropToOffset(huakuaidiv, Convert.ToInt32(yidongjuli) + 10, 0).Build().Perform(); for (int i = 0; i < 5; i++) { Thread.Sleep(2000);
if (driver.Url == "http://cdcs.qgil.net/index") break; } if (driver.Url == "http://cdcs.qgil.net/index") { var Cookies = driver.Manage().Cookies; var cookie = Cookies.GetCookieNamed("Admin-Token").Value; if (!string.IsNullOrEmpty(cookie)) { List<Fly_ManifestUser> List = db.Queryable<Fly_ManifestUser>().Where(p => p.Type == "QG青港" && p.Account == this._ConfigItem.QG_Account).ToList(); foreach (var item in List) { item.Cookie = cookie; item.CookieDate = DateTime.Now; db.Updateable(item).ExecuteCommand(); } addLog("青港cookie更新成功------" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "QG-青港"); } } } } }
driver.Quit(); driver.Dispose(); service.Dispose();
|