Exemplo n.º 1
0
        // 홈 이동
        private void MoveHome()
        {
            IWebElement element = CssSelector.FindElement(driver, ".naver_logo, .logo_naver, .link_naver, .h_logo");

            if (element == null)
            {
                if (PROP.AGENT.GetType() == Agent.AGENT_TYPE_PC)
                {
                    driver.Navigate().GoToUrl(Url.CONST_DEFAULT_PC_START_URL);
                }
                else
                {
                    driver.Navigate().GoToUrl(Url.CONST_DEFAULT_MOBILE_START_URL);
                }
            }
            else
            {
                element.Click();
            }

            PROP.LOCATION.SetLocation(Location.HOME);
        }
Exemplo n.º 2
0
        private bool MoveCategory()
        {
            int         index   = 0;
            IWebElement element = null;

            //index = convertStringToTabIndex(category);

            if (PROP.LOCATION.GetLocation() == Location.HOME)
            {
                if (PROP.AGENT.GetType() == Agent.AGENT_TYPE_PC)
                {
                    //string className = TabIndexToMainTabClassName(index);
                    element = CssSelector.FindElement(driver, string.Format(".{0}", PROP.LOCATION.CATEGORY.mainClass));

                    if (element == null)
                    {
                        return(false);
                    }

                    try
                    {
                        element.Click();
                    }
                    catch (Exception e)
                    {
                        driver.FindElement(By.XPath("//*[@id='_nx_lnb_more']/a")).Click();
                        Thread.Sleep(300);
                        element.Click();
                    }
                }
                else
                {
                    //FIX 모바일 쪽은 나중에 수정
                    element = driver.FindElement(By.CssSelector(string.Format("li a[href*='{0}']", PROP.LOCATION.CATEGORY.m_menu)));
                    doScroll(1000, -200, 1);
                    element.Click();
                }
            }

            if (PROP.LOCATION.GetLocation() == Location.SEARCH)
            {
                if (PROP.AGENT.GetType() == Agent.AGENT_TYPE_PC)
                {
                    element = CssSelector.FindElement(driver, string.Format(".lnb_menu li.lnb{0}", PROP.LOCATION.CATEGORY.index));

                    if (element == null)
                    {
                        return(false);
                    }

                    try
                    {
                        element.Click();
                    }
                    catch (Exception e)
                    {
                        driver.FindElement(By.XPath("//*[@id='_nx_lnb_more']/a")).Click();
                        Thread.Sleep(300);
                        element.Click();
                    }
                }
                else
                {
                    string value = PROP.LOCATION.CATEGORY.m_menu;
                    element = driver.FindElement(By.CssSelector(string.Format("li a[href*='{0}']", PROP.LOCATION.CATEGORY.m_menu)));
                    doScroll(1000, -200, 1);
                    element.Click();
                }
            }

            PROP.LOCATION.CATEGORY.SetCategory(PROP.LOCATION.CATEGORY.name);
            return(true);
        }
Exemplo n.º 3
0
        // 검색 백그라운드 쓰레드
        public void SearchRankingBackGround()
        {
            try
            {
                pictureBox3.Invoke(new Action(delegate()
                {
                    pictureBox3.BackgroundImage = global::Winner.Properties.Resources.BB;
                }));


                ChromeOptions cOptions = new ChromeOptions();
                cOptions.AddArguments("disable-infobars");
                cOptions.AddArguments("--js-flags=--expose-gc");
                cOptions.AddArguments("--enable-precise-memory-info");
                cOptions.AddArguments("enable-popup-blocking");
                cOptions.AddArguments("--disable-default-apps");
                cOptions.AddArguments("--headless");

                // 서비스 초기화
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
                chromeDriverService.HideCommandPromptWindow = true;

                driver = new ChromeDriver(chromeDriverService, cOptions);

                //var service = PhantomJSDriverService.CreateDefaultService();
                //service.SslProtocol = "any"; //"any" also works
                //service.HideCommandPromptWindow = true;
                //driver = new PhantomJSDriver(service);

                //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");

                //// 서비스 초기화
                //ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
                //chromeDriverService.HideCommandPromptWindow = true;

                //driver = new ChromeDriver(chromeDriverService, cOptions);


                DataGridViewRowCollection rows = dataGridView1.Rows;

                for (int i = 0; i < rows.Count; i++)
                {
                    DataGridViewRow            row   = rows[i];
                    DataGridViewCellCollection cells = row.Cells;
                    string keyword    = (string)cells[HEADER_KEYWORD].Value;
                    string subKeyword = (string)cells[HEADER_SUB_KEYWORD].Value;

                    driver.Navigate().GoToUrl("https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=" + HttpUtility.UrlEncode(keyword));

                    IWebElement unfold   = CssSelector.FindElement(driver, ".unfold");
                    bool        isRanked = false;

                    if (unfold != null)
                    {
                        if (unfold.Displayed)
                        {
                            unfold.Click();
                        }
                        IReadOnlyCollection <IWebElement> elements = driver.FindElements(By.CssSelector(".lst_relate a"));
                        int currentWidth = 0;
                        int line         = 0;


                        for (int j = 0; j < elements.Count; j++)
                        {
                            IWebElement element = elements.ElementAt(j);
                            IWebElement li      = element.FindElement(By.XPath("./.."));
                            string      WIDTH   = li.GetCssValue("width");

                            int cusorWIDTH = (int)double.Parse(WIDTH.Substring(0, WIDTH.IndexOf("px"))) + 13;

                            currentWidth += cusorWIDTH;

                            if (currentWidth > 460)
                            {
                                currentWidth = cusorWIDTH;
                                line++;
                            }

                            if (element.Text.Equals(subKeyword))
                            {
                                isRanked = true;

                                dataGridView1.Invoke(new Action(delegate()
                                {
                                    row.Cells[HEADER_RANKING].Value     = element.GetAttribute("data-idx");
                                    row.Cells[HEADER_UPDATE_DATE].Value = DateTime.Now.ToString("yyyy-MM-dd hh:mm");
                                    if (line >= 2)
                                    {
                                        row.Cells[HEADER_IS_MORE].Value = "N";
                                    }
                                    else
                                    {
                                        row.Cells[HEADER_IS_MORE].Value = "Y";
                                    }
                                }));

                                currentWidth = 0;
                                break;
                            }
                        }
                    }

                    if (!isRanked)
                    {
                        row.Cells[HEADER_RANKING].Value     = "*";
                        row.Cells[HEADER_UPDATE_DATE].Value = DateTime.Now.ToString("yyyy-MM-dd hh:mm");
                        row.Cells[HEADER_IS_MORE].Value     = "N/A";
                    }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                PhantomJSClose();
            }
        }