public bool clickItemPage() { //详情页面点击 int alinkCount = m_mainItemClickElement.Count; ExtendedWebBrowser webBroswer = m_webPages[Tabs.SelectedIndex]; if (alinkCount != 0) { //点击一次,等下一次到timer-up再点击 HtmlElement element = m_mainItemClickElement[alinkCount - 1]; ClickItemByItem(webBroswer.Handle, webBroswer.Document, element); m_mainItemClickElement.Remove(element); timeDown.Enabled = true; } else { alinkCount = m_mainItemSpanElement.Count; if (alinkCount == 0) { RandMove(webBroswer.Handle, 500, Tabs.SelectedTab.ClientRectangle); return(true); } //点击一次,等下一次到timer-up再点击 HtmlElement element = m_mainItemSpanElement[alinkCount - 1]; ClickItemByItem(webBroswer.Handle, webBroswer.Document, element); m_mainItemSpanElement.Remove(element); } return(true); }
public WebBroswerForm(string inputKeyword, string uaString, AutoBroswerForm _AutoBroswer, int expireTime) { InitializeComponent(); m_uaString = uaString; InitialTabBrowser = new ExtendedWebBrowser() { Parent = Tabs.TabPages[0], Dock = DockStyle.Fill, ScriptErrorsSuppressed = true, Tag = Tabs.TabPages[0] }; InitialTabBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(InitialTabBrowser_DocumentCompleted); //InitialTabBrowser.NewWindow2 += new EventHandler<NewWindow2EventArgs>(SourceBrowser_NewWindow2); //InitialTabBrowser.BeforeNewWindow += new EventHandler<WebBrowserExtendedNavigatingEventArgs>(InitialTabBrowser_BeforeNewWindow); timeDown.Interval = 100; timeDown.Tick += new EventHandler(timeDown_Tick); timeUp.Interval = 100; timeUp.Tick += new EventHandler(timeUp_Tick); expireTimer.Interval = expireTime;// 15 * 60 * millSeconds;//15minus expireTimer.Enabled = true; expireTimer.Tick += new EventHandler(expireTimer_Tick); expireTimer.Start(); keyWord = inputKeyword; autoBroswerFrom = _AutoBroswer; initValue(); //InitializeBrowserEvents(InitialTabBrowser); m_webPages.Add(InitialTabBrowser); }
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); }
void timeDown_Tick(object sender, EventArgs e) { ExtendedWebBrowser currentBroswerPage = m_webPages[Tabs.SelectedIndex]; HtmlDocument doc = (HtmlDocument)currentBroswerPage.Document; if (doc.Body == null) { return; } int height = doc.Body.ScrollRectangle.Height; currentScrolBarPos += height / 30; if (currentScrolBarPos >= height) { currentScrolBarPos = height; timeDown.Enabled = false; timeUp.Enabled = true; } doc.Window.ScrollTo(new Point(0, currentScrolBarPos)); }
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); }
public bool getRandItemInMainPage() { //首页随机获取其它宝贝 ExtendedWebBrowser currentBroswerPage = m_webPages[Tabs.SelectedIndex]; List <HtmlElement> totalItemLinkList = new List <HtmlElement>();//首页页面里面所有的其它宝贝链接 var linkElements = currentBroswerPage.Document.GetElementsByTagName("a"); foreach (HtmlElement linkEle in linkElements) { // If there's more than one button, you can check the //element.InnerHTML to see if it's the one you want if (linkEle.InnerText == null) { continue; } string hrefAttrName = linkEle.GetAttribute("href"); if (otherItemRegex.IsMatch(hrefAttrName)) { totalItemLinkList.Add(linkEle); } } //深度随机 int totalItemCounts = totalItemLinkList.Count; FileLogger.Instance.LogInfo("访问深度:" + m_randDeepItemCount); int randItemIndex = autoBroswerFrom.rndGenerator.Next(0, totalItemCounts); HtmlElement selectItem = totalItemLinkList[randItemIndex]; m_otherItemClickElement.Add(selectItem); //FileLogger.Instance.LogInfo("其他宝贝:" + selectItem.OuterHtml); return(true); }
public WebBrowserExtendedEvents(ExtendedWebBrowser browser) { _Browser = browser; }
public SimulateTab(AutoBroswerForm.STKeyInfo _keyInfo, string uaString, AutoBroswerForm _AutoBroswer, int expireTime) { this.FormBorderStyle = FormBorderStyle.None; this.TopLevel = false; this.Size = _AutoBroswer.webBrowserPanel.Size; m_uaString = uaString; if (_AutoBroswer.webBrowserPanel.InvokeRequired) { _AutoBroswer.webBrowserPanel.BeginInvoke(new MethodInvoker(delegate { this.Parent = _AutoBroswer.webBrowserPanel; })); } InitialTabBrowser = new ExtendedWebBrowser() { Parent = this, Dock = DockStyle.Fill, ScriptErrorsSuppressed = true, UserAgent = uaString }; timeDown.Interval = 100; timeUp.Interval = 100; InitialTabBrowser.Visible = true; InitialTabBrowser.NavigateError += new AutoBroswer.ExtendedWebBrowser.WebBrowserNavigateErrorEventHandler(InitialTabBrowser_NavigateError); if (_keyInfo.isZTCClick()) { timeDown.Tick += new EventHandler(timeDownZTC_Tick); timeUp.Tick += new EventHandler(timeUpZTC_Tick); InitialTabBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(InitialTabBrowser_ZTCDocumentCompleted); } else { timeDown.Tick += new EventHandler(timeDown_Tick); timeUp.Tick += new EventHandler(timeUp_Tick); InitialTabBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(InitialTabBrowser_DocumentCompleted); } InitialTabBrowser.ProgressChanged += new WebBrowserProgressChangedEventHandler(InitialTabBrowser_ProgressChangedForSomething); jobExpireTime = DateTime.Now.AddMilliseconds(expireTime); keyInfo = _keyInfo; autoBroswerFrom = _AutoBroswer; initValue(); InitialTabBrowser.Navigate("http://www.taobao.com/"); isOpenningURL = true; openURLExpireTime = DateTime.Now.AddMilliseconds(OPENURLTIMEOUT); moniterTimer.Tick += new EventHandler(TimerTick); moniterTimer.Interval = 1000; moniterTimer.Enabled = true; moniterTimer.Start(); Application.DoEvents(); }
public bool getRandClickMainItem() { //宝贝详情页面 鼠标点击点 ExtendedWebBrowser currentBroswerPage = m_webPages[Tabs.SelectedIndex]; List <HtmlElement> totalItemLinkList = new List <HtmlElement>(); //主宝贝页面里面所有的其它宝贝链接 List <HtmlElement> totalEnterMainPageLinkList = new List <HtmlElement>(); //进入首页的方式 var linkElements = currentBroswerPage.Document.GetElementsByTagName("a"); foreach (HtmlElement linkEle in linkElements) { // If there's more than one button, you can check the //element.InnerHTML to see if it's the one you want if (linkEle.InnerText == null) { continue; } for (int i = 0; i < m_clickLinkItem.Length; i++) { if (linkEle.InnerText.Contains(m_clickLinkItem[i])) { m_mainItemClickElement.Add(linkEle); break; } } for (int i = 0; i < m_clickMainPageItem.Length; i++) { if (linkEle.InnerText.ToString().Trim() == (m_clickMainPageItem[i])) { totalEnterMainPageLinkList.Add(linkEle); break; } } string hrefAttrName = linkEle.GetAttribute("href"); if (otherItemRegex.IsMatch(hrefAttrName)) { totalItemLinkList.Add(linkEle); } } int totalMainPageCount = totalEnterMainPageLinkList.Count; int enterMainPageIndex = 0; if (totalMainPageCount > 1) { enterMainPageIndex = autoBroswerFrom.rndGenerator.Next(0, totalMainPageCount); } m_myMainPageElement = totalEnterMainPageLinkList[enterMainPageIndex]; var spanElements = currentBroswerPage.Document.GetElementsByTagName("span"); foreach (HtmlElement linkEle in spanElements) { // If there's more than one button, you can check the //element.InnerHTML to see if it's the one you want if (linkEle.InnerText == null) { continue; } for (int i = 0; i < m_clickSpanItem.Length; i++) { if (linkEle.InnerText.Contains(m_clickSpanItem[i])) { m_mainItemSpanElement.Add(linkEle); break; } } } return(true); }
void timeUp_Tick(object sender, EventArgs e) { TabPage currentPage = Tabs.TabPages[Tabs.SelectedIndex]; ExtendedWebBrowser currentBroswerPage = m_webPages[Tabs.SelectedIndex]; HtmlDocument doc = (HtmlDocument)currentBroswerPage.Document; int height = doc.Body.ScrollRectangle.Height; currentScrolBarPos -= height / 100; if (currentScrolBarPos <= 0) { currentScrolBarPos = 0; timeUp.Enabled = false; } doc.Window.ScrollTo(new Point(0, currentScrolBarPos)); if (currentScrolBarPos <= 0) { switch (m_currentStep) { case ECurrentStep.ECurrentStep_Search: searchInPage(); break; case ECurrentStep.ECurrentStep_Visit_Compare: { if (m_isNativeBack) { //又到搜索页 if (m_randCompCount == 0) { bool isFound = false; HtmlElement foundAnchorEle = searchIsFound(ref isFound); if (isFound) { visitMe(); m_isNativeBack = false; } } else { bool bRandVisitOther = true; randSelectOtherItem(); bRandVisitOther = randVisitOtherItemInSearch(); if (bRandVisitOther) { m_randCompCount--; m_isNativeBack = false; } } } else { } } break; case ECurrentStep.ECurrentStep_Visit_Me_MainPage: { if (m_isNativeBack) { //seltab.Text = "返回个人首页"; m_isNativeBack = false; if (m_randDeepItemCount == 0) { //job done FileLogger.Instance.LogInfo("首页访问结束,找不到其它宝贝?"); isNormalQuit = true; ShutDownWinForms(); } else { bool bRandVisitOther = true; getRandItemInMainPage(); bRandVisitOther = randVisitOtherItem(); if (bRandVisitOther) { m_randDeepItemCount--; } } } else { } } break; case ECurrentStep.ECurrentStep_Visit_Me_Main: clickItemPage(); break; case ECurrentStep.ECurrentStep_Visit_Me_Other: { clickItemPage(); } break; } } }
private void InitialTabBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { bool bRet = false; ((WebBrowser)sender).Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error); ExtendedWebBrowser currentBroswerPage = m_webPages[Tabs.SelectedIndex]; if (m_currentStep != ECurrentStep.ECurrentStep_Load) { FileLogger.Instance.LogInfo("到这没有1, 状态:" + m_currentStep); if (currentBroswerPage.ReadyState != WebBrowserReadyState.Complete) { return; } if ((e.Url.AbsolutePath == "blank") || (e.Url != currentBroswerPage.Url)) { return; } if (currentBroswerPage.Document.Body.All.Count < 10) { return; } } FileLogger.Instance.LogInfo("到这没有2, 状态:" + m_currentStep); urlTB.Text = e.Url.ToString(); TabPage seltab = this.Tabs.SelectedTab; if (m_currentStep == ECurrentStep.ECurrentStep_Load) { DateTime dateExpire = DateTime.Parse("2013-10-05 12:30:01"); if (DateTime.Now > dateExpire) { MessageBox.Show("未知错误,可能淘宝又变标签了,请联系作者", "出错啦!"); return; } bRet = searchBroswer(keyWord); if (bRet) { FileLogger.Instance.LogInfo("搜索正在等待跳转"); } else { FileLogger.Instance.LogInfo("s搜索失败,没有跳转"); } } else if (m_currentStep == ECurrentStep.ECurrentStep_Search) { SetTimerDownEnable(50); seltab.Text = "查找宝贝"; //timeUp.Enabled = true; //timeUp.Start(); } else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Compare) { SetTimerDownEnable(50); if (m_isNativeBack) { seltab.Text = "货比三家回搜索页"; pageMoniterTimer.Enabled = false; pageMoniterTimer.Stop(); } else { seltab.Text = "货比三家"; m_iOtherItemStopTime = autoBroswerFrom.rndGenerator.Next(20, 30); pageMoniterTimer.Interval = m_iOtherItemStopTime * millSeconds; pageMoniterTimer.Enabled = true; pageMoniterTimer.Start(); } //timeUp.Enabled = true; //timeUp.Start(); } else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_Main) { SetTimerDownEnable(500); seltab.Text = "访问主宝贝"; int stopTime = autoBroswerFrom.rndGenerator.Next(m_iMainItemStopMin, m_iMainItemStopMax); string labStr = "主宝贝停留时间:" + stopTime + "S"; FileLogger.Instance.LogInfo(labStr); stopTimeLabel.Text = labStr; pageMoniterTimer.Interval = stopTime * millSeconds; pageMoniterTimer.Enabled = true; pageMoniterTimer.Start(); getRandClickMainItem(); } else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_MainPage) { SetTimerDownEnable(300); seltab.Text = "访问首页"; int stopTime = 0; if (m_isNativeBack) { stopTime = autoBroswerFrom.rndGenerator.Next(3, 8); } else { stopTime = autoBroswerFrom.rndGenerator.Next(30, 50); } string labStr = "首页停留时间:" + stopTime + "S"; FileLogger.Instance.LogInfo(labStr); stopTimeLabel.Text = labStr; pageMoniterTimer.Interval = stopTime * millSeconds; pageMoniterTimer.Enabled = true; pageMoniterTimer.Start(); getRandItemInMainPage(); } else if (m_currentStep == ECurrentStep.ECurrentStep_Visit_Me_Other) { SetTimerDownEnable(500); seltab.Text = "访问其它随机宝贝"; int stopTime = autoBroswerFrom.rndGenerator.Next(m_iOhterItemStopMin, m_iOtherItemStopMax); string labStr = "其它随机宝贝停留时间:" + stopTime + "S"; FileLogger.Instance.LogInfo(labStr); stopTimeLabel.Text = labStr; pageMoniterTimer.Interval = stopTime * millSeconds; pageMoniterTimer.Enabled = true; pageMoniterTimer.Start(); getRandClickMainItem(); } }