1. 브라우저 옵션 추가 삽입 및 교정
This commit is contained in:
@@ -113,17 +113,28 @@ namespace NaverSearcher
|
||||
|
||||
m_WebSocket.OnError += (sender, e) =>
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine(e.Message);
|
||||
Console.WriteLine(e.Message);
|
||||
|
||||
if (m_Thread.ThreadState != ThreadState.Unstarted)
|
||||
{
|
||||
m_Thread.Join();
|
||||
}
|
||||
|
||||
Thread.Sleep(m_Random.Next(10000, 30000));
|
||||
|
||||
m_WebSocket.Close();
|
||||
};
|
||||
|
||||
m_WebSocket.OnClose += (sender, e) =>
|
||||
{
|
||||
System.Diagnostics.Trace.WriteLine(e.Reason);
|
||||
Console.WriteLine(e.Reason);
|
||||
|
||||
if (m_Thread.ThreadState != ThreadState.Unstarted)
|
||||
{
|
||||
m_Thread.Join();
|
||||
}
|
||||
|
||||
Thread.Sleep(2000);
|
||||
Thread.Sleep(m_Random.Next(10000, 30000));
|
||||
|
||||
m_WebSocket.Connect();
|
||||
};
|
||||
@@ -270,8 +281,13 @@ namespace NaverSearcher
|
||||
_ChromeOptions.AddArguments("--disable-popup-blocking");
|
||||
_ChromeOptions.AddArguments("--disable-default-apps");
|
||||
_ChromeOptions.AddArguments("--headless");
|
||||
_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");
|
||||
*/
|
||||
_ChromeOptions.AddArguments("start-maximized");
|
||||
_ChromeOptions.AddArguments("--window-size=1920x1080");
|
||||
_ChromeOptions.AddArguments("--lang=ko_KR");
|
||||
_ChromeOptions.AddArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36");
|
||||
_ChromeOptions.AddArguments("--app-version=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515");
|
||||
|
||||
_ChromeOptions.BinaryLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SmartSearch\\chrome.exe";
|
||||
|
||||
// 프록시 설정
|
||||
@@ -286,9 +302,7 @@ namespace NaverSearcher
|
||||
ChromeDriverService _ChromeDriverService = ChromeDriverService.CreateDefaultService();
|
||||
_ChromeDriverService.HideCommandPromptWindow = true;
|
||||
|
||||
ChromeDriver _ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
|
||||
|
||||
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(5));
|
||||
bool bResult = false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -300,6 +314,10 @@ namespace NaverSearcher
|
||||
// 스크롤 내린다.
|
||||
// 20 ~ 60초 대기
|
||||
|
||||
ChromeDriver _ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
|
||||
|
||||
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(5));
|
||||
|
||||
try
|
||||
{
|
||||
_ChromeDriver.Navigate().GoToUrl(@"https://naver.com");
|
||||
@@ -350,7 +368,7 @@ namespace NaverSearcher
|
||||
|
||||
SearchWait(_ChromeDriver);
|
||||
|
||||
ReadOnlyCollection<IWebElement> links = _ChromeDriver.FindElements(By.CssSelector("a[href*='https://']"));
|
||||
ReadOnlyCollection <IWebElement> links = _ChromeDriver.FindElements(By.CssSelector("a[href*='https://']"));
|
||||
|
||||
int _try = links.Count;
|
||||
|
||||
@@ -387,21 +405,31 @@ namespace NaverSearcher
|
||||
{
|
||||
Console.WriteLine("=== 검색어 ===");
|
||||
Console.WriteLine(ex.Message);
|
||||
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
bResult = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("=== 검색어 페어 ===");
|
||||
Console.WriteLine(ex.Message);
|
||||
|
||||
bResult = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ChromeDriver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
// 결과 던지기
|
||||
using (WebSocket _WebSocket = new WebSocket("ws://api.inrose.com"))
|
||||
using (WebSocket _WebSocket = new WebSocket(xFF))
|
||||
{
|
||||
_WebSocket.OnOpen += (sender, e) => {
|
||||
_WebSocket.Send("{\"GUID\":\"" + Properties.Settings.Default.GUID + "\", \"keyword\":" + _JObject + ", \"done\":true}");
|
||||
_WebSocket.Send("{\"GUID\":\"" + Properties.Settings.Default.GUID + "\", \"keyword\":" + _JObject + ", \"done\":" + bResult.ToString().ToLower() + "}");
|
||||
};
|
||||
|
||||
_WebSocket.OnMessage += (sender, e) => {
|
||||
@@ -424,119 +452,7 @@ namespace NaverSearcher
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ChromeDriver.Quit();
|
||||
}
|
||||
}
|
||||
|
||||
private void Excute(JObject _JObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
|
||||
var elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
var source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.open();");
|
||||
|
||||
_ChromeDriver.SwitchTo().Window(_ChromeDriver.WindowHandles[1]);
|
||||
|
||||
string winHandleBefore = _ChromeDriver.CurrentWindowHandle;
|
||||
//_ChromeDriver.SwitchTo().Window(winHandleBefore);
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
|
||||
elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
_ChromeDriver.SwitchTo().Window(_ChromeDriver.WindowHandles[1]);
|
||||
|
||||
winHandleBefore = _ChromeDriver.CurrentWindowHandle;
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
|
||||
elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
_ChromeDriver.Navigate().GoToUrl(@"https://inrose.com");
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
|
||||
elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
_ChromeDriver.SwitchTo().Window(_ChromeDriver.WindowHandles.First());
|
||||
|
||||
winHandleBefore = _ChromeDriver.CurrentWindowHandle;
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
|
||||
elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
_ChromeDriver.Navigate().GoToUrl(@"https://google.com");
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
|
||||
elem = _ChromeDriver.FindElementByXPath("//*");
|
||||
source_code = elem.GetAttribute("outerHTML");
|
||||
|
||||
return;
|
||||
|
||||
_ChromeDriver.Navigate().GoToUrl(@"https://www.instagram.com/");
|
||||
|
||||
_WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
|
||||
//_WebDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
|
||||
|
||||
string _id_xpath = "//*[@id=\"loginForm\"]/div/div[1]/div/label/input";
|
||||
string _pass_xpath = "//*[@id=\"loginForm\"]/div/div[2]/div/label/input";
|
||||
string _login_xpath = "//*[@id=\"loginForm\"]/div/div[3]/button/div";
|
||||
|
||||
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_login_xpath)));
|
||||
|
||||
_ChromeDriver.FindElement(By.XPath(_id_xpath)).SendKeys(@"leeumdkj@gmail.com");
|
||||
_ChromeDriver.FindElement(By.XPath(_pass_xpath)).SendKeys(@"awdr1536!!");
|
||||
_ChromeDriver.FindElement(By.XPath(_login_xpath)).Click();
|
||||
|
||||
// 알림 존재시
|
||||
|
||||
string _alert_xpath = "//*[@id=\"react-root\"]/section/main/div/div/div/div/button";
|
||||
|
||||
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_alert_xpath)));
|
||||
|
||||
try
|
||||
{
|
||||
_ChromeDriver.FindElement(By.XPath(_alert_xpath)).Click();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
_alert_xpath = "/html/body/div[4]/div/div/div/div[3]/button[2]";
|
||||
|
||||
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_alert_xpath)));
|
||||
|
||||
try
|
||||
{
|
||||
_ChromeDriver.FindElement(By.XPath(_alert_xpath)).Click();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
//_search_xpath = "//*[@id=\"react-root\"]/section/nav/div[2]/div/div/div[2]/input";
|
||||
|
||||
//_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_search_xpath)));
|
||||
|
||||
//_ChromeDriver.FindElement(By.XPath(_search_xpath)).SendKeys(@"인플 검색");
|
||||
|
||||
*/
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("=== 실행 ===");
|
||||
Console.WriteLine(ex.Message);
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user