우아한 프로그래밍
반응형
article thumbnail
[C#] Invoke, InvokeRequired, BeginInvoke의 차이에 대해 알아보자
프로그래밍/C# 2019. 1. 23. 09:30

1. 개념 Invoke, InvokeRequired, BeginInvoke 의 개념 모두 C# Form 프로그맹을 하면서 나오는 용어들이다. 해당 용어들을 이해하기 위해서는 쓰레드에 대한 개념이해가 선행이 되어야한다. 기본적으로 C# Form 프로그래밍에서는 MainThread(UI Thread) OtherThread( Work Thread)로 분리되어 작업이 된다. 폼컨트롤 제어와 작업을 분리되어 하지 않고 MainThread가 모든 작업을 맡아 한다면 MainThread가 작업을 처리하는동안 사용자가 보고있는 Form이 반응 안하는 것처럼 느껴지고 실제로도 멈춰있게 된다. 그래서 분리해서 작업을 하게 된다. 그럼 위 3가지의 개념을 이해하기 위해 임의의 두 Thread가 있다고 가정하자. MainTh..

[C#] WebDriver 시크릿(Secret)모드 실행하기!
프로그래밍/C# 2019. 1. 14. 23:34

1. 사용방법 간단합니다 cOptions.AddArguments("--incognito"); 옵션 하나 추가해주시면됩니다. // 드라이버 생성 private IWebDriver MakeDriver(string ip) { ChromeOptions cOptions = new ChromeOptions(); cOptions.AddArguments("disable-infobars"); cOptions.AddArguments("--js-flags=--expose-gc"); cOptions.AddArguments("--enable-precise-memory-info"); cOptions.AddArguments("--disable-popup-blocking"); cOptions.AddArguments("--disabl..

[C#] 텍스트파일 여는 방법
프로그래밍/C# 2019. 1. 5. 07:04

1. 사용방법 System.Diagnostics.Process.Start("Notepad.exe", "./config/auth.txt");

article thumbnail
[C#] Selenium WebDriver, 특정 요소가 화면에 보일 때 까지 기다리기!
프로그래밍/C# 2019. 1. 5. 00:09

1. 비쥬얼스튜디오 세팅 NuGet 패키지 관리자에서 아래 그림의 빨간 네모 설치 2. 함수 private static bool WaitForVisivle(IWebDriver driver, By by) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); try { IWebElement element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by)); } catch (Exception e) { return false; } return true; } 3. 사용방법 WaitForVisivle(driver, By.CssSelector("..

[C#] Selenium WebDriver 자바스크립트 실행하기!
프로그래밍/C# 2019. 1. 5. 00:05

1. 함수 private void ExecuteScript( IWebDriver driver, string script) { var jse = (IJavaScriptExecutor)driver; jse.ExecuteScript(script, ""); } 2. 사용방법 // API 콤보 element = driver.FindElement(By.CssSelector("#content > div._1npwx1ZsSsDYAihmXQ9tSZ > div.app_w.v2._1RSI0ux8Px9ixMfxc83n_S > div > div.-hGhiZvdJWnjxwoynhvkL > div:nth-child(2) > div._1aFqXiCpPDTEGG-QVtlu3w.value-list-api > div > div > but..

[C#] Selenium WebDriver 느리게 입력 ( 타이핑 효과 주기)
프로그래밍/C# 2019. 1. 5. 00:01

1. 문제상황 Selenium WebDriver를 사용하여 입력을 보낼때 너무 빨리 입력되어 문제가 되는 경우가 간혹 있다. 따라서 사용자가 입력하는 것처럼 천천히 입력을 하는 함수를 만들었습니다. 2. 함수 private void SendKey(IWebElement element, string keyword, int delay){ char[] charArray = keyword.ToCharArray(); foreach (char c in charArray) { element.SendKeys(c.ToString()); Thread.Sleep(delay); } } 3. 사용방법 IWebElement element = driver.FindElement(By.ClassName("field-input")); S..

[C#] 파일 특정라인 변경하는 함수
프로그래밍/C# 2019. 1. 4. 23:58

1. 함수 static void LineChanger(string newText, string fileName, int line_to_edit) { string[] arrLine = File.ReadAllLines(fileName, Encoding.Default); arrLine[line_to_edit - 1] = newText; File.WriteAllLines(fileName, arrLine, Encoding.Default); } 2. 사용방법 // 데이터저장 LineChanger(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", authVO.username, authVO.password, authVO.company, authVO.url, authVO.apiKey, a..

[C#] 파일입력( StreamReader)하는 함수
프로그래밍/C# 2018. 12. 25. 15:38

1. 사용방법 private void readFile(string filePath) { string line; StreamReader file = new StreamReader(filePath, Encoding.Default, true); while ((line = file.ReadLine()) != null && !line.Equals("")) { // Do Something! } file.Close(); }

[C#] 프로세스(Process) 종료 하는 메소드
프로그래밍/C# 2018. 12. 25. 15:35

1. 사용방법 // 이미지 네임에 해당하는 모든 프로세스를 종료하는 메소드 private void ProcessKill(string imgName) { // 프로세스 종료 Process[] processes = Process.GetProcessesByName(imgName); foreach (var process in processes) { try { process.Kill(); } catch (Exception e) { } } }

[C#] Selenium ChromeDriver Option 옵션 정리 ( Proxy 변경법 포함)
프로그래밍/C# 2018. 12. 25. 15:29

1. 사용방법 // 드라이버 생성 private IWebDriver MakeDriver(string ip) { ChromeOptions cOptions = new ChromeOptions(); cOptions.AddArguments("disable-infobars"); cOptions.AddArguments("--js-flags=--expose-gc"); cOptions.AddArguments("--enable-precise-memory-info"); cOptions.AddArguments("--disable-popup-blocking"); cOptions.AddArguments("--disable-default-apps"); cOptions.AddArguments("--headless"); // 프록시..

반응형