From d0d1992a88b3486184389296f4485253ef120417 Mon Sep 17 00:00:00 2001 From: chodadoo Date: Sat, 7 Aug 2021 22:50:15 +0900 Subject: [PATCH] =?UTF-8?q?1.=20=EC=9E=85=EC=84=BC=EC=85=98=20=ED=91=9C?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DCinside_Cleaner/Program.cs | 170 +++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 81 deletions(-) diff --git a/DCinside_Cleaner/Program.cs b/DCinside_Cleaner/Program.cs index 848ded0..f9d7115 100644 --- a/DCinside_Cleaner/Program.cs +++ b/DCinside_Cleaner/Program.cs @@ -12,92 +12,100 @@ namespace DCinside_Cleaner { static void Main(string[] args) { - Console.Write("ID : "); - string _id = Console.ReadLine(); - Console.Write("PASSWORD : "); - string _pass = Console.ReadLine(); - Console.Write("글삭제 1, 댓글삭제 2 : "); - string _sel = Console.ReadLine(); - - if (_id == string.Empty || _pass == string.Empty || (_sel != "1" && _sel != "2")) + try { - Console.Write("입력 값 잘 못 됨"); + Console.Write("ID : "); + string _id = Console.ReadLine(); + Console.Write("PASSWORD : "); + string _pass = Console.ReadLine(); + Console.Write("글삭제 1, 댓글삭제 2 : "); + string _sel = Console.ReadLine(); + + if (_id == string.Empty || _pass == string.Empty || (_sel != "1" && _sel != "2")) + { + Console.Write("입력 값 잘 못 됨"); + return; + } + + ChromeOptions _ChromeOptions = new ChromeOptions(); + _ChromeOptions.AddArguments("disable-infobars"); + _ChromeOptions.AddArguments("--js-flags=--expose-gc"); + _ChromeOptions.AddArguments("--enable-precise-memory-info"); + _ChromeOptions.AddArguments("--disable-popup-blocking"); + _ChromeOptions.AddArguments("--disable-default-apps"); + _ChromeOptions.AddArguments("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); + + ChromeDriverService _ChromeDriverService = ChromeDriverService.CreateDefaultService(); + _ChromeDriverService.HideCommandPromptWindow = true; + + ChromeDriver _ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions); + + WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(5)); + + _ChromeDriver.Navigate().GoToUrl(@"https://www.dcinside.com/"); + + string _id_path = "//*[@id=\"user_id\"]"; + string _pass_path = "//*[@id=\"pw\"]"; + string _login_path = "//*[@id=\"login_ok\"]"; + _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_id_path))); + _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_pass_path))); + _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_login_path))); + + _ChromeDriver.FindElement(By.XPath(_id_path)).SendKeys(_id); + _ChromeDriver.FindElement(By.XPath(_pass_path)).SendKeys(_pass); + _ChromeDriver.FindElement(By.XPath(_login_path)).Click(); + + if (_sel == "1") + { + _ChromeDriver.Navigate().GoToUrl(@"https://gallog.dcinside.com/" + _id + "/posting?p=1"); + } + else + { + _ChromeDriver.Navigate().GoToUrl(@"https://gallog.dcinside.com/" + _id + "/comment?p=1"); + } + + string _del_btn = "/html/body/div[1]/div[2]/main/article/div/div[3]/section/div[1]/div/ul/li[1]/div/div/button"; + _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_del_btn))); + + while (true) + { + try + { + _ChromeDriver.FindElement(By.XPath(_del_btn)).Click(); + } + catch (Exception ex) + { + + } + + Thread.Sleep(100); + + try + { + _ChromeDriver.SwitchTo().Alert().Accept(); + } + catch (Exception ex) + { + + } + + Thread.Sleep(100); + + if (Console.KeyAvailable) + { + if (ConsoleKey.Escape == Console.ReadKey(true).Key) + break; + } + } + + _ChromeDriver.Quit(); + return; } - - ChromeOptions _ChromeOptions = new ChromeOptions(); - _ChromeOptions.AddArguments("disable-infobars"); - _ChromeOptions.AddArguments("--js-flags=--expose-gc"); - _ChromeOptions.AddArguments("--enable-precise-memory-info"); - _ChromeOptions.AddArguments("--disable-popup-blocking"); - _ChromeOptions.AddArguments("--disable-default-apps"); - _ChromeOptions.AddArguments("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"); - - ChromeDriverService _ChromeDriverService = ChromeDriverService.CreateDefaultService(); - _ChromeDriverService.HideCommandPromptWindow = true; - - ChromeDriver _ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions); - - WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(5)); - - _ChromeDriver.Navigate().GoToUrl(@"https://www.dcinside.com/"); - - string _id_path = "//*[@id=\"user_id\"]"; - string _pass_path = "//*[@id=\"pw\"]"; - string _login_path = "//*[@id=\"login_ok\"]"; - _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_id_path))); - _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_pass_path))); - _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_login_path))); - - _ChromeDriver.FindElement(By.XPath(_id_path)).SendKeys(_id); - _ChromeDriver.FindElement(By.XPath(_pass_path)).SendKeys(_pass); - _ChromeDriver.FindElement(By.XPath(_login_path)).Click(); - - if (_sel == "1") + catch (Exception ex) { - _ChromeDriver.Navigate().GoToUrl(@"https://gallog.dcinside.com/" + _id + "/posting?p=1"); - } else - { - _ChromeDriver.Navigate().GoToUrl(@"https://gallog.dcinside.com/" + _id + "/comment?p=1"); + Console.WriteLine("ERROR : " + ex.Message); } - - string _del_btn = "/html/body/div[1]/div[2]/main/article/div/div[3]/section/div[1]/div/ul/li[1]/div/div/button"; - _WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_del_btn))); - - while (true) - { - try - { - _ChromeDriver.FindElement(By.XPath(_del_btn)).Click(); - } - catch (Exception ex) - { - - } - - Thread.Sleep(100); - - try - { - _ChromeDriver.SwitchTo().Alert().Accept(); - } - catch (Exception ex) - { - - } - - Thread.Sleep(100); - - if (Console.KeyAvailable) - { - if (ConsoleKey.Escape == Console.ReadKey(true).Key) - break; - } - } - - _ChromeDriver.Quit(); - - return; } } }