public bool Wait(TenDayBrowser parent, int waitTime) { if (this._status == IEStatus.IEStatus_Wait) { TimeSpan span = (TimeSpan)(this._now - this._beforeWaitTime); if (span.TotalSeconds >= this._waitTime) { this._status = IEStatus.IEStatus_None; return true; } if ((this._curTenDayBrowser != null) && (this._curTenDayBrowser.Document != null)) { mshtml.IHTMLDocument2 domDocument = (mshtml.IHTMLDocument2)this._curTenDayBrowser.Document.DomDocument; if (domDocument != null) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); this.MoveMouseToBottom(windowHwnd, domDocument); } } } else if (this._status == IEStatus.IEStatus_None) { parent.ShowTip2("等待 " + waitTime + " 秒"); this._status = IEStatus.IEStatus_Wait; this._waitTime = waitTime; this._beforeWaitTime = this._now; } else { return true; } return false; }
public bool SysWait(TenDayBrowser parent) { TimeSpan span = (TimeSpan)(this._now - this._beforeWaitTime); double totalSeconds = span.TotalSeconds; if (totalSeconds >= TenDayBrowser.SYSTEMWAITTIME) { this._beforeWaitTime = this._now; this._status = IEStatus.IEStatus_None; return true; } parent.ShowTip4("等待网页加载" + totalSeconds.ToString()); return false; }
public bool Update(TenDayBrowser parent) { bool flag = false; this._now = DateTime.Now; TimeSpan span = (TimeSpan)(this._now - this._startTaskTime); if (span.TotalMinutes > 20.0) { this._errorString = "任务超时"; this._threadRun = false; } if (this._threadRun) { try { if (this._status == IEStatus.IEStatus_SysWait) { flag = this.SysWait(parent); } else if (this._status == IEStatus.IEStatus_SysComplete) { flag = this.SysWaitForComplete(); } else if (this._curTenDayBrowser != null) { flag = this.ParseItems(parent); } } catch (Exception exception) { flag = true; Logger.Error(exception); } if (this._errorString != string.Empty) { this._threadRun = false; } if (flag) { this.ResetTaskTime(); this._inputClickTaobaoCloseButton = false; this._randomClickLinkCount = 0; this._status = IEStatus.IEStatus_None; if (this._threadRun && (this._task.GetTaskInfo(ref this._taskInfo, ref this._taskInfoIndex, ref this._startLoop, ref this._loop, ref this._loopTime) != 0)) { if (!this._isCompleted) { this._isCompleted = true; this._status = IEStatus.IEStatus_SysComplete; } else { this._threadRun = false; } } } this.CheckDocCompletTimeOut(); } if (!this._threadRun) { parent.ShowTip2("任务结束"); parent.ShowTip3(""); parent.ShowTip4(""); return true; } return false; }
public bool DeepClick(TenDayBrowser parent, string clickCount, string waitTime, string keyword) { bool flag = false; mshtml.IHTMLDocument2 domDocument = (mshtml.IHTMLDocument2)this._curTenDayBrowser.Document.DomDocument; if (this._status == IEStatus.IEStatus_Wait) { TimeSpan span = (TimeSpan)(this._now - this._beforeWaitTime); if (span.TotalSeconds >= this._waitTime) { flag = this.GetDeepClickLinkInfo(parent, domDocument, keyword); } else if (domDocument != null) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); this.MoveMouseToBottom(windowHwnd, domDocument); } } else if (this._status == IEStatus.IEStatus_None) { if (this._loopTime >= WindowUtil.StringToInt(clickCount)) { this._loop = false; flag = true; } else { this._status = IEStatus.IEStatus_Wait; this._waitTime = WindowUtil.StringToInt(waitTime); this._beforeWaitTime = this._now; parent.ShowTip2(string.Concat(new object[] { "深入点击第", this._loopTime + 1, "次,等待", waitTime, "秒" })); } } else if (this._status == IEStatus.IEStatus_MoveToDest) { bool isClick = false; bool isFind = false; parent.ShowTip2(string.Concat(new object[] { "深入点击第", this._loopTime + 1, "次:", this._randomClickLink })); this.ClickLink(parent, this._randomClickLink, string.Empty, ((int)this._randomClickLinkTag).ToString(), this._randomClickLinkIndex.ToString(), ref isFind, ref isClick, false, false, ref this._randomClickLinkCount); if (isClick || (this._randomClickLinkCount >= 100)) { this._status = IEStatus.IEStatus_None; flag = true; } else if ((this._randomClickLinkCount % 10) == 9) { this._randomClickLinkCount++; this.ResetTaskTime(); flag = this.GetDeepClickLinkInfo(parent, domDocument, keyword); } } else { flag = true; } if (domDocument != null) { Marshal.ReleaseComObject(domDocument); } return flag; }
public void ResetBrowserComplete() { this._status = IEStatus.IEStatus_SysWait; this._scrollTime = this._beforeWaitTime = this._waitFindTime = this._now; }
private bool GetDeepClickLinkInfo(TenDayBrowser parent, mshtml.IHTMLDocument2 doc2, string keyword) { bool flag = false; if (((this._curTenDayBrowser != null) && (this._curTenDayBrowser.Document != null)) && (doc2 != null)) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); int clientWidth = 0; int clientHeight = 0; int scrollWidth = 0; int scrollHeight = 0; mshtml.IHTMLElement2 element = HtmlUtil.GetWindowWidthAndHeight(windowHwnd, doc2, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight); mshtml.IHTMLElementCollection links = doc2.links; ArrayList list = new ArrayList(); if (string.IsNullOrEmpty(keyword)) { keyword = ""; } Regex regex = new Regex(keyword + @"(\w)?"); foreach (mshtml.IHTMLElement element2 in links) { if ((((element2.getAttribute("href", 0) != null) && (element2.getAttribute("target", 0) != null)) && element2.getAttribute("target", 0).ToString().ToLower().Equals("_blank")) && (string.IsNullOrEmpty(keyword) || regex.IsMatch(element2.getAttribute("href", 0).ToString()))) { Rectangle elementRect = HtmlUtil.GetElementRect(doc2.body, element2); if ((((elementRect.Height > 0) && (elementRect.Width > 0)) && (((elementRect.X + element.scrollLeft) > 0) && ((elementRect.X + element.scrollLeft) < scrollWidth))) && (((elementRect.Y + element.scrollTop) > 0) && ((elementRect.Y + element.scrollTop) < scrollHeight))) { list.Add(element2); } } } if (list.Count > 0) { Random random = new Random(); int num5 = random.Next(list.Count); random = null; mshtml.IHTMLElement ele = list[num5] as mshtml.IHTMLElement; if (!string.IsNullOrEmpty(ele.outerText) && !string.IsNullOrEmpty(ele.outerText.Trim())) { this._randomClickLink = ele.outerText; this._randomClickLinkTag = ElementTag.outerText; } else { this._randomClickLinkTag = ElementTag.href; this._randomClickLink = ele.getAttribute("href", 0).ToString(); } this._randomClickLinkIndex = HtmlUtil.GetLinkElementIndex(doc2, ele, this._randomClickLink, ((int)this._randomClickLinkTag).ToString()); this._status = IEStatus.IEStatus_MoveToDest; this._beforeWaitTime = this._now; list = null; random = null; return flag; } if (doc2 != null) { this.MoveMouseToBottom(windowHwnd, doc2); if (this.MoveTimeOut() && this.FindTimeOut()) { parent.ShowTip2("不存在 " + keyword); this._loop = false; flag = true; } } return flag; } if (this.FindTimeOut()) { flag = true; } return flag; }
private bool VisitPage(TenDayBrowser parent, string compareTime, string keyword2, string tagStr, string indexStr) { bool flag = false; if (isFirstEnterPage) { resetPageParameter(); isFirstEnterPage = false; } mshtml.IHTMLDocument2 domDocument = (mshtml.IHTMLDocument2)this._curTenDayBrowser.Document.DomDocument; IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); if (this._status == IEStatus.IEStatus_Wait) { try { if (shouldScroll) { int height = _curTenDayBrowser.Document.Body.ScrollRectangle.Height; if (!isScrollUp) { scrollPos += height / 100; if (scrollPos >= height) { scrollPos = height; isScrollUp = true; } } else { scrollPos -= height / 100; if (scrollPos <= 0) { scrollPos = 0; isScrollUp = false; shouldScroll = false; } } _curTenDayBrowser.Document.Window.ScrollTo(new Point(0, scrollPos)); } else { //随机提取内页点击目标 if (clickIndex < clickLinkItem.Length) { flag = GetPageClickLinkInfo(parent, domDocument, clickIndex); if (flag) { clickIndex++; } return false; } } } catch (System.Exception ex) { _errorString = ex.Message; } } else if (this._status == IEStatus.IEStatus_None) { this._status = IEStatus.IEStatus_Wait; this._waitTime = WindowUtil.StringToInt("0"); this._beforeWaitTime = this._now; parent.ShowTip2(string.Concat(new object[] { "开始点击我了啦" })); } else if (this._status == IEStatus.IEStatus_MoveToDest) { bool isClick = false; bool isFind = false; parent.ShowTip2(string.Concat(new object[] { "进入我的店铺了" })); ClickLink(parent, this._randomClickLink, string.Empty, ((int)this._randomClickLinkTag).ToString(), this._randomClickLinkIndex.ToString(), ref isFind, ref isClick, false, false, ref this._randomClickLinkCount); if (isClick) { this._status = IEStatus.IEStatus_None; shouldScroll = true; } if (!isClick && IsPageTimeOut(int.Parse(compareTime))) { parent.ShowTip2("点击不到超链接 \"" + _randomClickLink + "\""); this._errorString = this._errorString + "点击不到超链接 \"" + _randomClickLink; isFind = false; flag = true; } } if (IsPageTimeOut(int.Parse(compareTime))) { resetPageParameter(); flag = true; } if (domDocument != null) { Marshal.ReleaseComObject(domDocument); } return flag; }
//private bool GetPageClickLinkInfo(TenDayBrowser parent, mshtml.IHTMLDocument2 doc2, string linkName, string tagStr) //{ // bool flag = false; // if (((this._curTenDayBrowser != null) && (this._curTenDayBrowser.Document != null)) && (doc2 != null)) // { // IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); // int clientWidth = 0; // int clientHeight = 0; // int scrollWidth = 0; // int scrollHeight = 0; // mshtml.IHTMLElement2 element = HtmlUtil.GetWindowWidthAndHeight(windowHwnd, doc2, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight); // mshtml.IHTMLElementCollection links = doc2.links; // ArrayList list = new ArrayList(); // ElementTag iD = ElementTag.ID; // if ((tagStr != string.Empty) && (tagStr != "")) // { // iD = (ElementTag)WindowUtil.StringToInt(tagStr); // } // foreach (mshtml.IHTMLElement element2 in links) // { // if ((((element2.getAttribute("href", 0) != null) && (element2.getAttribute("target", 0) != null)) && element2.getAttribute("target", 0).ToString().ToLower().Equals("_blank")) && // HtmlUtil.IsElementMatch(element2, iD, wangwangName, "") // ) // { // Rectangle elementRect = HtmlUtil.GetElementRect(doc2.body, element2); // if ((((elementRect.Height > 0) && (elementRect.Width > 0)) && (((elementRect.X + element.scrollLeft) > 0) && ((elementRect.X + element.scrollLeft) < scrollWidth))) && (((elementRect.Y + element.scrollTop) > 0) && ((elementRect.Y + element.scrollTop) < scrollHeight))) // { // list.Add(element2); // } // } // } // if (list.Count == 1) // { // mshtml.IHTMLElement ele = list[0] as mshtml.IHTMLElement; // try // { // mshtml.IHTMLElement itemBoxEle = ele.parentElement.parentElement.parentElement; // IHTMLElementCollection children = itemBoxEle.children as mshtml.IHTMLElementCollection; // foreach (IHTMLElement div in children) // { // if (div.className == "summary") // { // IHTMLElementCollection children2 = div.children as mshtml.IHTMLElementCollection; // foreach (IHTMLElement ele2 in children2) // { // if (ele2.tagName == "a") // { // ele = ele2; // break; // } // } // break; // } // } // } // catch (System.Exception ex) // { // // // return false; // } // if (!string.IsNullOrEmpty(ele.outerText) && !string.IsNullOrEmpty(ele.outerText.Trim())) // { // this._randomClickLink = ele.outerText; // this._randomClickLinkTag = ElementTag.outerText; // } // else // { // this._randomClickLinkTag = ElementTag.href; // this._randomClickLink = ele.getAttribute("href", 0).ToString(); // } // this._randomClickLinkIndex = HtmlUtil.GetLinkElementIndex(doc2, ele, this._randomClickLink, ((int)this._randomClickLinkTag).ToString()); // this._status = IEStatus.IEStatus_MoveToDest; // this._beforeWaitTime = this._now; // list = null; // flag = true; // return flag; // } // if (doc2 != null) // { // this.MoveMouseToBottom(windowHwnd, doc2); // if (this.MoveTimeOut() && this.WaitTimeOut()) // { // parent.ShowTip2("不存在标签 :" + tagStr + " 的店铺:" + wangwangName); // this._loop = false; // flag = true; // } // } // return flag; // } // if (this.WaitTimeOut()) // { // flag = true; // } // return flag; //} private bool GetPageClickLinkInfo(TenDayBrowser parent, mshtml.IHTMLDocument2 doc2, int index) { bool flag = false; if (((this._curTenDayBrowser != null) && (this._curTenDayBrowser.Document != null)) && (doc2 != null)) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); int clientWidth = 0; int clientHeight = 0; int scrollWidth = 0; int scrollHeight = 0; mshtml.IHTMLElement2 element = HtmlUtil.GetWindowWidthAndHeight(windowHwnd, doc2, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight); mshtml.IHTMLElementCollection links = doc2.links; ArrayList list = new ArrayList(); string outText = clickLinkItem[index]; foreach (mshtml.IHTMLElement element2 in links) { if (element2.innerText != null && element2.innerText.ToLower().Trim().Contains(outText)) { Rectangle elementRect = HtmlUtil.GetElementRect(doc2.body, element2); if ((((elementRect.Height > 0) && (elementRect.Width > 0)) && (((elementRect.X + element.scrollLeft) > 0) && ((elementRect.X + element.scrollLeft) < scrollWidth))) && (((elementRect.Y + element.scrollTop) > 0) && ((elementRect.Y + element.scrollTop) < scrollHeight))) { list.Add(element2); } } } if (list.Count == 1) { mshtml.IHTMLElement ele = list[0] as mshtml.IHTMLElement; if (!string.IsNullOrEmpty(ele.outerText) && !string.IsNullOrEmpty(ele.outerText.Trim())) { this._randomClickLink = ele.outerText; this._randomClickLinkTag = ElementTag.outerText; } else { this._randomClickLinkTag = ElementTag.href; this._randomClickLink = outText; } this._randomClickLinkIndex = HtmlUtil.GetLinkElementIndex(doc2, ele, this._randomClickLink, ((int)this._randomClickLinkTag).ToString()); this._status = IEStatus.IEStatus_MoveToDest; this._beforeWaitTime = this._now; list = null; flag = true; return flag; } if (doc2 != null) { this.MoveMouseToBottom(windowHwnd, doc2); if (this.MoveTimeOut() && this.WaitTimeOut()) { parent.ShowTip2("不存在标签 :" + outText); this._loop = false; flag = true; } } return flag; } if (this.WaitTimeOut()) { flag = true; } return flag; }
private bool GetMEClickLinkInfo(TenDayBrowser parent, mshtml.IHTMLDocument2 doc2, string wangwangName, string tagStr) { bool flag = false; if (((this._curTenDayBrowser != null) && (this._curTenDayBrowser.Document != null)) && (doc2 != null)) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); int clientWidth = 0; int clientHeight = 0; int scrollWidth = 0; int scrollHeight = 0; mshtml.IHTMLElement2 element = HtmlUtil.GetWindowWidthAndHeight(windowHwnd, doc2, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight); mshtml.IHTMLElementCollection links = doc2.links; ArrayList list = new ArrayList(); ElementTag iD = ElementTag.ID; if ((tagStr != string.Empty) && (tagStr != "")) { iD = (ElementTag) WindowUtil.StringToInt(tagStr); } foreach (mshtml.IHTMLElement element2 in links) { if ((((element2.getAttribute("href", 0) != null) && (element2.getAttribute("target", 0) != null)) && element2.getAttribute("target", 0).ToString().ToLower().Equals("_blank")) && HtmlUtil.IsElementMatch(element2, iD, wangwangName, "") ) { Rectangle elementRect = HtmlUtil.GetElementRect(doc2.body, element2); if ((((elementRect.Height > 0) && (elementRect.Width > 0)) && (((elementRect.X + element.scrollLeft) > 0) && ((elementRect.X + element.scrollLeft) < scrollWidth))) && (((elementRect.Y + element.scrollTop) > 0) && ((elementRect.Y + element.scrollTop) < scrollHeight))) { list.Add(element2); } } } if (list.Count == 1) { mshtml.IHTMLElement ele = list[0] as mshtml.IHTMLElement; try { mshtml.IHTMLElement itemBoxEle = ele.parentElement.parentElement.parentElement; IHTMLElementCollection children = itemBoxEle.children as mshtml.IHTMLElementCollection; foreach (IHTMLElement div in children) { if (div.className == "summary") { IHTMLElementCollection children2 = div.children as mshtml.IHTMLElementCollection; foreach (IHTMLElement ele2 in children2) { if (ele2.tagName.ToLower().Trim() == "a") { ele = ele2; break; } } break; } } } catch (System.Exception ex) { // return false; } if (!string.IsNullOrEmpty(ele.outerText) && !string.IsNullOrEmpty(ele.outerText.Trim())) { this._randomClickLink = ele.outerText; this._randomClickLinkTag = ElementTag.outerText; } else { this._randomClickLinkTag = ElementTag.href; this._randomClickLink = ele.getAttribute("href", 0).ToString(); } this._randomClickLinkIndex = HtmlUtil.GetLinkElementIndex(doc2, ele, this._randomClickLink, ((int)this._randomClickLinkTag).ToString()); this._status = IEStatus.IEStatus_MoveToDest; this._beforeWaitTime = this._now; list = null; flag = true; return flag; } if (doc2 != null) { this.MoveMouseToBottom(windowHwnd, doc2); if (this.MoveTimeOut() && this.WaitTimeOut()) { parent.ShowTip2("不存在标签 :" + tagStr + " 的店铺:" + wangwangName); this._loop = false; flag = true; } } return flag; } if (this.WaitTimeOut()) { flag = true; } return flag; }
private bool ClickMePage(TenDayBrowser parent, string wangwang, string keyword2, string tagStr, string indexStr) { bool flag = false; mshtml.IHTMLDocument2 domDocument = (mshtml.IHTMLDocument2)this._curTenDayBrowser.Document.DomDocument; if (this._status == IEStatus.IEStatus_Wait) { //GetRandClickLinkInfo(parent, domDocument, keyword1, keyword2); TimeSpan span = (TimeSpan)(this._now - this._beforeWaitTime); if (span.TotalSeconds >= this._waitTime) { flag = GetMEClickLinkInfo(parent, domDocument, wangwang, tagStr); } else if (domDocument != null) { IntPtr windowHwnd = GetWindowHwnd(this._curTenDayBrowser.Handle.ToInt32()); this.MoveMouseToBottom(windowHwnd, domDocument); } return false; } else if (this._status == IEStatus.IEStatus_None) { this._status = IEStatus.IEStatus_Wait; this._waitTime = WindowUtil.StringToInt("0"); this._beforeWaitTime = this._now; parent.ShowTip2(string.Concat(new object[] { "开始点击我了啦" })); } else if (this._status == IEStatus.IEStatus_MoveToDest) { flag = false; bool isClick = false; bool isFind = false; parent.ShowTip2(string.Concat(new object[] { "进入我的店铺了" })); ClickLink(parent, this._randomClickLink, string.Empty, ((int)this._randomClickLinkTag).ToString(), this._randomClickLinkIndex.ToString(), ref isFind, ref isClick, false, false, ref this._randomClickLinkCount); if (isClick) { ResetBrowserComplete(); this._status = IEStatus.IEStatus_None; flag = true; } } else { flag = true; } if (domDocument != null) { Marshal.ReleaseComObject(domDocument); } return flag; }