static void Main(string[] args) { ini ini = new ini(); #if DEBUG #else string Check = ini.GetIni("Info", "Lastlogin-Datetime"); Log("Start:" + DateTime.Now.ToString()); if (Check == DateTime.Now.ToShortDateString()) { Environment.Exit(0); } #endif string ID = ini.GetIni("Login", "ID"); string PW = ini.GetIni("Login", "PW"); if (ID == "" || PW == "") { Console.Write("ID:"); ID = Console.ReadLine(); Console.Write("PW:"); PW = Console.ReadLine(); } IWebDriver driver = new ChromeDriver(); driver.Url = "https://www.aniplustv.com/login/login.asp?reURL=%23/default.asp%3FgCode%3DMA%26sCode%3D000"; //로그인 bool Login = false; while (!Login) { IWebElement context = driver.FindElement(By.Name("userid")); context.Clear(); context.SendKeys(ID); //아이디 입력 context = driver.FindElement(By.Name("password")); context.Clear(); context.SendKeys(PW); //비밀번호 입력 driver.FindElement(By.Id("btnLogin")).Click(); //로그인 버튼 클릭 while (true) { IAlert Alert = SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent().Invoke(driver); if (Alert != null) //팝업창이 있는지 { Console.Clear(); Console.WriteLine("로그인 실패:" + Alert.Text); Alert.Accept(); Console.Write("ID:"); ID = Console.ReadLine(); Console.Write("PW:"); PW = Console.ReadLine(); break; } if (IsElementPresent(driver, By.ClassName("id"))) //로그인 성공해서 닉네임이 존재하는지 { IWebElement Name = driver.FindElement(By.ClassName("id")); ini.SetIni("Login", "ID", ID); ini.SetIni("Login", "PW", PW); ini.SetIni("Info", "Lastlogin-Datetime", DateTime.Now.ToShortDateString()); Log(Name.Text + "-로그인 성공"); Login = true; break; } System.Threading.Thread.Sleep(1000); } } driver.Quit(); driver.Dispose(); Log("Success"); Environment.Exit(0); }
static void Main(string[] args) { ini ini = new ini(); Log("Start:" + DateTime.Now.ToString()); #if DEBUG #else string Check = ini.GetIni("Info", "Lastlogin-Datetime"); if (Check == DateTime.Now.ToShortDateString()) { Environment.Exit(0); } #endif string ID = ini.GetIni("Login", "ID"); string PW = ini.GetIni("Login", "PW"); if (ID == "" || PW == "") { Console.Write("ID:"); ID = Console.ReadLine(); Console.Write("PW:"); PW = Console.ReadLine(); } IWebDriver driver = new ChromeDriver(); driver.Url = "https://www.aniplustv.com/login/login.asp"; //Login url driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); IWebElement context = driver.FindElement(By.Name("userid")); context.Clear(); context.SendKeys(ID); //아이디 입력 context = driver.FindElement(By.Name("password")); context.Clear(); context.SendKeys(PW); //비밀번호 입력 driver.FindElement(By.Id("btnLogin")).Click(); //로그인 버튼 클릭 IAlert alert = null; bool login = false; while ((alert = SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent().Invoke(driver)) == null && !(login = IsElementPresent(driver, By.CssSelector("#open_user > a > span.id")))) { System.Threading.Thread.Sleep(10); } if (alert != null) //팝업창이 있는지 { Console.Clear(); Console.WriteLine("로그인 실패:" + alert.Text); Console.WriteLine("아이디 비번 입력후 수동으로 재실행 해주세요."); alert.Accept(); Console.Write("ID:"); ID = Console.ReadLine(); Console.Write("PW:"); PW = Console.ReadLine(); ini.SetIni("Login", "ID", ID); ini.SetIni("Login", "PW", PW); } if (login) //로그인 성공해서 닉네임이 존재하는지 { IWebElement Name = driver.FindElement(By.CssSelector("#open_user > a > span.id")); ini.SetIni("Login", "ID", ID); ini.SetIni("Login", "PW", PW); ini.SetIni("Info", "Lastlogin-Datetime", DateTime.Now.ToShortDateString()); Log(Name.Text + "-로그인 성공"); } else if (ini.GetIni("Debug", "debug") == "1") { Log(driver.PageSource); } System.Threading.Thread.Sleep(1000); driver.Quit(); driver.Dispose(); Log("Success"); Environment.Exit(0); }