Commit fa09a4b1 authored by 黄奎's avatar 黄奎

111

parent f24495c8
using EduSpider.Spiders.SchoolHouseKeeper;
using OpenQA.Selenium;
using System;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Threading;
using TicketSpider.Spiders.ClassInRule;
......@@ -35,5 +37,60 @@ namespace EduSpider
Console.ReadLine();
Environment.Exit(0);
}
#region 异常 退出chromedriver
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
/// <summary>
/// 获取窗口句柄
/// </summary>
/// <returns></returns>
public IntPtr GetWindowHandle()
{
string name = (Environment.CurrentDirectory + "\\chromedriver.exe");
IntPtr hwd = FindWindow(null, name);
return hwd;
}
/// <summary>
/// 关闭chromedriver窗口
/// </summary>
public void CloseWindow()
{
try
{
IntPtr hwd = GetWindowHandle();
SendMessage(hwd, 0x10, 0, 0);
}
catch
{
}
}
/// <summary>
/// 退出chromedriver
/// </summary>
/// <param name="driver"></param>
public void CloseChromeDriver(IWebDriver driver)
{
try
{
driver.Quit();
driver.Dispose();
}
catch
{
}
CloseWindow();
}
#endregion 异常 退出chromedriver
}
}
\ No newline at end of file
......@@ -68,7 +68,7 @@ namespace TicketSpider.Spiders.ClassInRule
IWebElement pwdEle;
var option = new ChromeOptions();
option.AddArgument("--incognito");
option.AddArgument("headless");
//option.AddArgument("headless");
option.AddArgument("disable-infobars");
option.AddArgument("window-size=1920,1080");
option.AddArgument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36");
......@@ -101,11 +101,11 @@ namespace TicketSpider.Spiders.ClassInRule
var login = BeginSliderLoginHandler(ref driver);
if (login.IsCompleted)
{
driver.SwitchTo().DefaultContent();
Thread.Sleep(1000 * 5);
//driver.SwitchTo().DefaultContent();
Console.WriteLine($"操作完成,正在等待结果");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"操作完成,正在等待结果");
//睡眠1秒,等待跳转
Thread.Sleep(5 * 1000);
if (driver.Url.Contains("www.eeo.cn/cn/login"))
{
Console.WriteLine($"模拟登录失败,准备重新执行...");
......@@ -129,9 +129,9 @@ namespace TicketSpider.Spiders.ClassInRule
}
else
{
Thread.Sleep(3 * 1000);
var cookies = driver.Manage().Cookies.AllCookies;
//处理
foreach (var item in driver.Manage().Cookies.AllCookies)
foreach (var item in cookies)
{
_loginCookies += item.Name + "=" + item.Value + ";";
}
......@@ -153,8 +153,11 @@ namespace TicketSpider.Spiders.ClassInRule
{
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"获取cooki失败,{ex.Message}");
Console.WriteLine($"获取cooki失败,{ex.Message}");
Thread.Sleep(1000 * 4);
}
driver.Close();
driver.Quit();
driver.Dispose();
Console.WriteLine("完成登录...");
VTX.FW.Helper.LogHelper.WriteInfo("RunAsync", $"完成登录...");
return flag;
......@@ -196,20 +199,25 @@ namespace TicketSpider.Spiders.ClassInRule
var d1 = Math.Round(bgX * 0.8);
var d2 = Math.Round(bgX * 0.1);
var d3 = Math.Round(bgX * 0.1);
Console.WriteLine("d1:" + d1);
action.MoveByOffset((int)d1, 1);
Thread.Sleep(new Random().Next(100) + 150);
Console.WriteLine("d2:" + d2);
action.MoveByOffset((int)d2, 1);
Thread.Sleep(new Random().Next(100) + 150);
Console.WriteLine("d3:" + d3);
action.MoveByOffset((int)d3, 1);
action.MoveByOffset((bgX - (int)d1 - (int)d2 - (int)d3), 1);
int last = (bgX - (int)d1 - (int)d2 - (int)d3);
Console.WriteLine("last:" + last);
action.MoveByOffset(last, 1);
Thread.Sleep(2000);
#endregion
action.Release(sliderButton);
action.Build().Perform();
driver.SwitchTo().DefaultContent();
}
File.Delete(fileBgPath);
......@@ -243,7 +251,7 @@ namespace TicketSpider.Spiders.ClassInRule
var dirpath = $"{Environment.CurrentDirectory}\\geetest";
Cv2.ImWrite($"{dirpath}\\{DateTime.Now.Ticks}.png", bgImg);
return maxLoc.X - 20;
return maxLoc.X - 25;
}
private static void HeartLine()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment