Ejemplo n.º 1
0
        public bool searchBroswer(string keyword)
        {
            HtmlDocument document = ((HtmlDocument)InitialTabBrowser.Document);
            HtmlElement  textArea = document.GetElementById("q");

            if (textArea == null)
            {
                FileLogger.Instance.LogInfo("找不到搜索输入框标签");
                return(false);
            }
            textArea.InnerText = keyword;

            var elements = document.GetElementsByTagName("button");

            foreach (HtmlElement searchBTN in elements)
            {
                // If there's more than one button, you can check the
                //element.InnerHTML to see if it's the one you want
                string className = searchBTN.GetAttribute("className");
                if (className == "btn-search" || searchBTN.InnerText == "搜 索")
                {
                    int randX = autoBroswerFrom.rndGenerator.Next(0, searchBTN.OffsetRectangle.Width - 1);
                    int randY = autoBroswerFrom.rndGenerator.Next(0, searchBTN.OffsetRectangle.Height - 1);

                    Rectangle rect = wbElementMouseSimulate.GetElementRect(document.Body.DomElement as mshtml.IHTMLElement, searchBTN.DomElement as mshtml.IHTMLElement);
                    Point     p    = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
                    RandMove(InitialTabBrowser.Handle, 1000, rect);
                    ClickOnPointInClient(InitialTabBrowser.Handle, p);
                    m_currentStep = ECurrentStep.ECurrentStep_Search;
                    return(true);
                }
            }
            FileLogger.Instance.LogInfo("找不到搜索按钮标签");
            return(false);
        }
Ejemplo n.º 2
0
        public bool enterMainPage()
        {
            if (m_myMainPageElement == null)
            {
                return(false);
            }
            ExtendedWebBrowser webBroswer = m_webPages[Tabs.SelectedIndex];

            m_myMainPageElement.SetAttribute("target", "_top");
            ClickItemByItem(webBroswer.Handle, webBroswer.Document, m_myMainPageElement);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_MainPage;
            return(true);
        }
Ejemplo n.º 3
0
        public bool searchInPage()
        {
            bool        isFound        = false;
            HtmlElement foundAnchorEle = searchIsFound(ref isFound);

            if (isFound)
            {
                FileLogger.Instance.LogInfo("在当前页:" + pageInfo + " 找到");
                randSelectOtherItem();
                randVisitOtherItemInSearch();
            }
            else
            {
                m_currentStep = ECurrentStep.ECurrentStep_Search;
                FileLogger.Instance.LogInfo("在当前页:" + pageInfo + ",没有找到,下一页继续");
                gotoNextPage();
            }
            return(true);
        }
Ejemplo n.º 4
0
        public bool visitMe()
        {
            if (m_myItemElement == null)
            {
                return(false);
            }

            HtmlElement itemBoxEle = getItemBoxElement(m_myItemElement);

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

            HtmlElement itemPicEle = itemBoxEle.All[0].All[0];

            itemPicEle.All[0].SetAttribute("target", "_top");
            ClickItemByPicBox(InitialTabBrowser.Handle, itemPicEle);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Main;
            return(true);
        }
Ejemplo n.º 5
0
        public bool randVisitOtherItem()
        {
            int leftVisitCount = m_otherItemClickElement.Count;

            if (leftVisitCount == 0)
            {
                return(false);//访问结束了
            }

            HtmlElement visitItem = m_otherItemClickElement[0];

            m_otherItemClickElement.Remove(visitItem);
            //Tabs.SelectTab(0);//返回 默认的Tab
            visitItem.SetAttribute("target", "_top");

            ExtendedWebBrowser currentWB = m_webPages[Tabs.SelectedIndex];

            ClickItemByItem(currentWB.Handle, currentWB.Document, visitItem);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Other;
            return(true);
        }
Ejemplo n.º 6
0
        //搜索页面随机
        public bool randVisitOtherItemInSearch()
        {
            int leftVisitCount = m_randItemElement.Count;

            if (leftVisitCount == 0)
            {
                FileLogger.Instance.LogInfo("货比三家结束了");
                return(false);//访问结束了
            }

            HtmlElement visitItem = m_randItemElement[0];

            visitItem.All[0].All[0].SetAttribute("target", "_top");

            m_randItemElement.Remove(visitItem);
            //FileLogger.Instance.LogInfo("开始浏览其他家的" + visitItem.OuterHtml);
            //Tabs.SelectTab(0);//返回 默认的Tab
            //InitialTabBrowser.Document.InvokeScript("eventFire", new object[] { visitItem.All[0].All[0] });
            ClickItemByPicBox(InitialTabBrowser.Handle, visitItem);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Compare;
            return(true);
        }
Ejemplo n.º 7
0
        public bool randVisitOtherItem()
        {
            int leftVisitCount = m_otherItemClickElement.Count;
            if (leftVisitCount == 0)
            {
                return false;//访问结束了
            }

            HtmlElement visitItem = m_otherItemClickElement[0];
            m_otherItemClickElement.Remove(visitItem);
            //Tabs.SelectTab(0);//返回 默认的Tab
            visitItem.SetAttribute("target", "_top");

            ExtendedWebBrowser currentWB = m_webPages[Tabs.SelectedIndex];
            ClickItemByItem(currentWB.Handle, currentWB.Document, visitItem);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Other;
            return true;
        }
Ejemplo n.º 8
0
 public bool enterMainPage()
 {
     if (m_myMainPageElement == null)
     {
         return false;
     }
     ExtendedWebBrowser webBroswer = m_webPages[Tabs.SelectedIndex];
     m_myMainPageElement.SetAttribute("target", "_top");
     ClickItemByItem(webBroswer.Handle, webBroswer.Document, m_myMainPageElement);
     m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_MainPage;
     return true;
 }
Ejemplo n.º 9
0
 public bool enterMainPage()
 {
     if (m_myMainPageElement == null)
     {
         return false;
     }
     m_myMainPageElement.SetAttribute("target", "_top");
     FileLogger.Instance.LogInfo("进入首页:" + m_myMainPageElement.InnerHtml);
     ClickItemByItem(InitialTabBrowser.Handle, InitialTabBrowser.Document, m_myMainPageElement);
     isOpenningURL = true;
     openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT);
     m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_MainPage;
     return true;
 }
Ejemplo n.º 10
0
        public void doMainJobZTC()
        {
            //bool bRet = false;
            FileLogger.Instance.LogInfo("当前文档状态:" + this.InitialTabBrowser.ReadyState);
            if ((m_currentStep != ECurrentStep.ECurrentStep_Load)
                && this.InitialTabBrowser.ReadyState != WebBrowserReadyState.Complete)
                return;
            //if (m_currentStep == ECurrentStep.ECurrentStep_Search && bFirstLoadSearch &&
            //    InitialTabBrowser.ReadyState != WebBrowserReadyState.Complete)
            //{
            //    return;
            //}
            string innerHtml = this.InitialTabBrowser.Document.Body.InnerHtml;
            string str1 = this.InitialTabBrowser.Document.Url.ToString();
            FileLogger.Instance.LogInfo("当前步骤:" + m_currentStep);
            //FileLogger.Instance.LogInfo("Cookie:" + InitialTabBrowser.Document.Cookie);
            autoBroswerFrom.URLTextBox.Text = str1;

            if (m_currentStep == ECurrentStep.ECurrentStep_Load)
            {
                DateTime dateExpire = DateTime.Parse("2013-12-29 02:30:01");
                if (DateTime.Now > dateExpire)
                {
                    MessageBox.Show("未知错误,可能淘宝又变标签了,请联系作者", "出错啦!");
                    return;
                }
                //bRet = searchBroswer(keyWord);
                if (str1.IndexOf("http://www.taobao.com/") > -1 && innerHtml.IndexOf("淘宝网首页") > -1)
                {
                    this.InitialTabBrowser.Document.GetElementById("q").InnerText = keyInfo.m_keyword;
                    this.InitialTabBrowser.Document.GetElementById("J_TSearchForm").InvokeMember("submit");
                    isOpenningURL = true;
                    m_lastStep = m_currentStep;
                    m_currentStep = ECurrentStep.ECurrentStep_Search;
                    openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT);
                    pageExpireTime = DateTime.Now.AddMilliseconds(ImpossibleTime);
                    lastURL = str1;
                }
            }
            else if (m_currentStep == ECurrentStep.ECurrentStep_Search)
            {

                if (str1.IndexOf("http://s.taobao.com/search") > -1 && innerHtml.IndexOf("所有分类") > -1 && m_lastStep == ECurrentStep.ECurrentStep_Load)
                {
                    ClickPrice();
                    bFirstLoadSearch = false;
                    m_lastStep = ECurrentStep.ECurrentStep_Search;
                    autoBroswerFrom.currentStep.Text = "查找宝贝";
                    pageExpireTime = DateTime.Now.AddMilliseconds(ImpossibleTime);
                    isOpenningURL = false;
                    lastURL = str1;
                }
                else if (str1.IndexOf("http://s.taobao.com/search") > -1 && innerHtml.IndexOf("所有分类") > -1)
                {
                    //if (str1.Contains("filter=reserve_price") == false)
                    //{
                    //    return;
                    //}
                    SetTimerDownEnable(5);
                    //searchInPage();
                    autoBroswerFrom.currentStep.Text = "查找宝贝";
                    pageExpireTime = DateTime.Now.AddMilliseconds(ImpossibleTime);
                    isOpenningURL = false;
                    lastURL = str1;
                }

            }
            else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Compare)
            {
                if (str1.IndexOf("http://s.taobao.com/search") > -1 && innerHtml.IndexOf("所有分类") > -1)
                {
                    SetTimerDownEnable(5);

                    autoBroswerFrom.currentStep.Text = "货比三家回搜索页";

                    pageExpireTime = DateTime.Now.AddMilliseconds(ImpossibleTime);
                    isOpenningURL = false;
                    //pageMoniterTimer.Enabled = false;
                    //pageMoniterTimer.Stop();
                }
                else if ((str1.IndexOf("http://item.taobao.com") > -1 || str1.IndexOf("http://detail.tmall.com") > -1) && innerHtml != "")
                {
                    SetTimerDownEnable(50);

                    autoBroswerFrom.currentStep.Text = "货比三家";

                    m_iOtherItemStopTime = autoBroswerFrom.rndGenerator.Next(7, 15);
                    pageExpireTime = DateTime.Now.AddMilliseconds(m_iOtherItemStopTime * millSeconds);
                    isOpenningURL = false;
                }

            }
            else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_Main)
            {
                SetTimerDownEnable(500);

                if (lastURL != str1)
                {
                    autoBroswerFrom.currentStep.Text = "访问主宝贝";

                    int stopTime = autoBroswerFrom.rndGenerator.Next(m_iMainItemStopMin, m_iMainItemStopMax);

                    string labStr = "主宝贝停留时间:" + stopTime + "S";
                    FileLogger.Instance.LogInfo(labStr);
                    autoBroswerFrom.stopTimeLabel.Text = labStr;

                    isOpenningURL = false;
                    pageExpireTime = DateTime.Now.AddMilliseconds(stopTime * millSeconds);
                    getRandClickMainItem();
                }

            }
            else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_MainPage)
            {
                SetTimerDownEnable(300);

                autoBroswerFrom.currentStep.Text = "访问首页";

                int stopTime = 0;
                if (m_isNativeBack)
                {
                    stopTime = autoBroswerFrom.rndGenerator.Next(3, 8);
                }
                else
                {
                    stopTime = autoBroswerFrom.rndGenerator.Next(8, 15);
                }
                string labStr = "首页停留时间:" + stopTime + "S";
                FileLogger.Instance.LogInfo(labStr);
                autoBroswerFrom.stopTimeLabel.Text = labStr;

                isOpenningURL = false;
                pageExpireTime = DateTime.Now.AddMilliseconds(stopTime * millSeconds);
            }
            else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_Other)
            {
                SetTimerDownEnable(500);
                if (lastURL != str1)
                {
                    autoBroswerFrom.currentStep.Text = "访问其它随机宝贝";

                    int stopTime = autoBroswerFrom.rndGenerator.Next(m_iOhterItemStopMin, m_iOtherItemStopMax);
                    string labStr = "其它随机宝贝停留时间:" + stopTime + "S";
                    FileLogger.Instance.LogInfo(labStr);
                    autoBroswerFrom.stopTimeLabel.Text = labStr;

                    isOpenningURL = false;
                    pageExpireTime = DateTime.Now.AddMilliseconds(stopTime * millSeconds);
                    getRandClickMainItem();
                }

            }
        }
Ejemplo n.º 11
0
        public bool visitMe()
        {
            if (m_myItemElement == null)
            {
                return false;
            }

            HtmlElement itemBoxEle = getItemBoxElement(m_myItemElement);
            if (itemBoxEle == null)
            {
                return false;
            }

            HtmlElement itemPicEle = itemBoxEle.All[0].All[0];
            itemPicEle.All[0].SetAttribute("target", "_top");
            ClickItemByPicBox(InitialTabBrowser.Handle, ref itemPicEle);
            isOpenningURL = true;
            openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Main;
            return true;
        }
Ejemplo n.º 12
0
        public bool searchInPage()
        {
            bool isFound = false;
            HtmlElement foundAnchorEle = searchIsFound(ref isFound);
            if (isFound)
            {
                FileLogger.Instance.LogInfo("在当前页:" + pageInfo + " 找到");
                randSelectOtherItem();
                randVisitOtherItemInSearch();

            }
            else
            {
                m_currentStep = ECurrentStep.ECurrentStep_Search;
                FileLogger.Instance.LogInfo("在当前页:" + pageInfo + ",没有找到,下一页继续");
                gotoNextPage();

            }
            return true;
        }
Ejemplo n.º 13
0
        //搜索页面随机
        public bool randVisitOtherItemInSearch()
        {
            var divCollect = InitialTabBrowser.Document.GetElementsByTagName("div");
            List<HtmlElement> colItemCollect = new List<HtmlElement>();
            foreach (HtmlElement el in divCollect)
            {
                string divClassAttr = el.GetAttribute("className");
                string nidString = el.GetAttribute("nid");
                if (divClassAttr.Trim().StartsWith("col item") && nidString != "")
                {
                    colItemCollect.Add(el);
                }
            }

            //HtmlElementCollection itemChilds = tbContentChildDIV.Children;//item box
            int itemListCount = colItemCollect.Count;
            if (itemListCount == 0)//查找出来的宝贝个数
            {
                return false;
            }

            int randIndex = autoBroswerFrom.rndGenerator.Next(0, itemListCount);

            HtmlElement itemElement = colItemCollect[randIndex];
            HtmlElement picBoxElement = getPicElement(itemElement);

            if (picBoxElement == null)
            {
                FileLogger.Instance.LogInfo("货比三家结束了");
                return false;//访问结束了
            }

            HtmlElement visitItem = picBoxElement;
            visitItem.All[0].All[0].SetAttribute("target", "_top");

            //FileLogger.Instance.LogInfo("开始浏览其他家的" + visitItem.OuterHtml);
            //Tabs.SelectTab(0);//返回 默认的Tab
            //InitialTabBrowser.Document.InvokeScript("eventFire", new object[] { visitItem.All[0].All[0] });
            ClickItemByPicBox(InitialTabBrowser.Handle, ref visitItem);
            isOpenningURL = true;
            openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Compare;
            return true;
        }
Ejemplo n.º 14
0
        public bool randVisitOtherItem()
        {
            //随机获取其它宝贝
            List<HtmlElement> totalItemLinkList = new List<HtmlElement>();//页面里面所有的其它宝贝链接

            var linkElements = InitialTabBrowser.Document.GetElementsByTagName("a");
            foreach (HtmlElement linkEle in linkElements)
            {
                if (linkEle.InnerText == null)
                {
                    continue;
                }
                string hrefAttrName = linkEle.GetAttribute("href");
                if (otherItemRegex.IsMatch(hrefAttrName) || otherTianMallRegex.IsMatch(hrefAttrName))
                {
                    totalItemLinkList.Add(linkEle);
                }

            }

            //深度随机
            int totalItemCounts = totalItemLinkList.Count;
            FileLogger.Instance.LogInfo("当前访问深度:" + m_randDeepItemCount);
            if (totalItemCounts == 0)
            {
                return false;
            }
            int randItemIndex = autoBroswerFrom.rndGenerator.Next(0, totalItemCounts);
            HtmlElement visitItem = totalItemLinkList[randItemIndex];
            if (visitItem == null)
            {
                return false;//访问结束了
            }
            visitItem.SetAttribute("target", "_top");

            ClickItemByItem(InitialTabBrowser.Handle, InitialTabBrowser.Document, visitItem);
            isOpenningURL = true;
            openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Other;
            return true;
        }
Ejemplo n.º 15
0
        //搜索页面随机
        public bool randVisitOtherItemInSearch()
        {
            int leftVisitCount = m_randItemElement.Count;
            if (leftVisitCount == 0)
            {
                FileLogger.Instance.LogInfo("货比三家结束了");
                return false;//访问结束了
            }

            HtmlElement visitItem = m_randItemElement[0];
            visitItem.All[0].All[0].SetAttribute("target", "_top");

            m_randItemElement.Remove(visitItem);
            //FileLogger.Instance.LogInfo("开始浏览其他家的" + visitItem.OuterHtml);
            //Tabs.SelectTab(0);//返回 默认的Tab
            //InitialTabBrowser.Document.InvokeScript("eventFire", new object[] { visitItem.All[0].All[0] });
            ClickItemByPicBox(InitialTabBrowser.Handle, visitItem);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Compare;
            return true;
        }
Ejemplo n.º 16
0
        public bool searchBroswer(string keyword)
        {
            HtmlDocument document = ((HtmlDocument)InitialTabBrowser.Document);
            HtmlElement textArea = document.GetElementById("q");
            if (textArea == null)
            {
                FileLogger.Instance.LogInfo("找不到搜索输入框标签");
                return false;
            }
            textArea.InnerText = keyword;

            var elements = document.GetElementsByTagName("button");
            foreach (HtmlElement searchBTN in elements)
            {
                // If there's more than one button, you can check the
                //element.InnerHTML to see if it's the one you want
                string className = searchBTN.GetAttribute("className");
                if (className == "btn-search" || searchBTN.InnerText == "搜 索")
                {
                    int randX = autoBroswerFrom.rndGenerator.Next(0, searchBTN.OffsetRectangle.Width - 1);
                    int randY = autoBroswerFrom.rndGenerator.Next(0, searchBTN.OffsetRectangle.Height - 1);

                    Rectangle rect = wbElementMouseSimulate.GetElementRect(document.Body.DomElement as mshtml.IHTMLElement, searchBTN.DomElement as mshtml.IHTMLElement);
                    Point p = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
                    RandMove(InitialTabBrowser.Handle, 1000, rect);
                    ClickOnPointInClient(InitialTabBrowser.Handle, p);
                    m_currentStep = ECurrentStep.ECurrentStep_Search;
                    return true;
                }
            }
            FileLogger.Instance.LogInfo("找不到搜索按钮标签");
            return false;
        }
Ejemplo n.º 17
0
        public bool searchBroswer(string keyword)
        {
            try
            {
                HtmlDocument document = ((HtmlDocument)InitialTabBrowser.Document);
                File.WriteAllText("search.txt", document.Body.OuterHtml.ToString(), Encoding.Default);
                HtmlElement textArea = document.GetElementById("q");
                if (textArea == null)
                {
                    FileLogger.Instance.LogInfo("找不到搜索输.入框标签");
                    return false;
                }
                FileLogger.Instance.LogInfo("before setInnerText");
                textArea.InnerText = keyword;
                FileLogger.Instance.LogInfo("after setInnerText");

                var elements = document.GetElementsByTagName("button");
                foreach (HtmlElement searchBTN in elements)
                {
                    string className = searchBTN.GetAttribute("className");
                    if (className == "btn-search" || searchBTN.InnerText == "搜 索")
                    {
                        FileLogger.Instance.LogInfo("found search button");
                        Rectangle rect = wbElementMouseSimulate.GetElementRect(document.Body.DomElement as mshtml.IHTMLElement, searchBTN.DomElement as mshtml.IHTMLElement);
                        Point p = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2);
                        RandMove(InitialTabBrowser.Handle, 1000, rect);
                        ClickOnPointInClient(InitialTabBrowser.Handle, p);
                        isOpenningURL = true;
                        m_currentStep = ECurrentStep.ECurrentStep_Search;
                        return true;
                    }
                }
                FileLogger.Instance.LogInfo("找不到搜索按钮标签");
                return false;
            }
            catch (System.Exception ex)
            {
                FileLogger.Instance.LogInfo("CatchError:" + ex.Message);
            }
            return false;
        }
Ejemplo n.º 18
0
        public bool visitMe()
        {
            if (m_myItemElement == null)
            {
                return false;
            }

            HtmlElement itemBoxEle = getItemBoxElement(m_myItemElement);
            if (itemBoxEle == null)
            {
                return false;
            }

            HtmlElement itemPicEle = itemBoxEle.All[0].All[0];
            itemPicEle.All[0].SetAttribute("target", "_top");
            ClickItemByPicBox(InitialTabBrowser.Handle, itemPicEle);
            m_currentStep = ECurrentStep.ECurrentStep_Visit_Me_Main;
            return true;
        }
Ejemplo n.º 19
0
        public bool searchInZTCPage()
        {
            bool isFound = false;
            HtmlElement foundAnchorEle = searchIsFoundZTC(ref isFound);
            if (isFound)
            {
                FileLogger.Instance.LogInfo("在当前页:" + currentPage + " 找到");
                if (m_randCompCount != 0)
                {
                    //randSelectOtherItem();
                    randVisitOtherItemInSearch();
                    m_randCompCount--;
                }
                else
                {
                    visitMe();
                }
            }
            else
            {
                m_currentStep = ECurrentStep.ECurrentStep_Search;
                FileLogger.Instance.LogInfo("在当前页:" + currentPage + ",没有找到,下一页继续");
                if (currentPage >= keyInfo.m_startPage && currentPage <= keyInfo.m_endPage)
                {
                    gotoNextPage();
                }
                else if (currentPage <= keyInfo.m_endPage)
                {
                    //jump to startpage
                    jumpToPage(keyInfo.m_startPage);
                }
                else
                {
                    //stop search
                    jobExpireTime = DateTime.Now.AddMilliseconds(-10 * 1000);
                }

            }
            return true;
        }