public static mshtml.IHTMLElement GetInputElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr) { mshtml.IHTMLElementCollection o = (mshtml.IHTMLElementCollection)doc.all.tags("input"); mshtml.IHTMLElement element = null; ElementTag iD = ElementTag.ID; int num = 0; int num2 = 0; if (!string.IsNullOrEmpty(indexStr)) { num = WindowUtil.StringToInt(indexStr); } if ((tagStr != string.Empty) && (tagStr != "")) { iD = (ElementTag)WindowUtil.StringToInt(tagStr); } foreach (mshtml.IHTMLElement element2 in o) { if (IsElementMatch(element2, iD, itemName, "")) { if (num2 == num) { element = element2; break; } num2++; } } if (o != null) { Marshal.ReleaseComObject(o); } return(element); }
private void FullScreen_Click(object sender, RoutedEventArgs e) { SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); IntPtr handle = GetForegroundWindow(); foreach (SHDocVw.WebBrowser IE in shellWindows) { if (IE.HWND.Equals(handle.ToInt32())) { doc = IE.Document as mshtml.HTMLDocument; } } if (doc != null) { mshtml.IHTMLElementCollection elemColl = null; elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement elem in elemColl) { if (elem.getAttribute("class") != null) { if (elem.className == "ytp-size-button ytp-button") { elem.click(); Console.WriteLine("yy"); break; } } } } }
public void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { //throw new NotImplementedException(); mshtml.HTMLDocument doc = webBrowser.Document as mshtml.HTMLDocument; mshtml.IHTMLElementCollection coll = (mshtml.IHTMLElementCollection)(doc.getElementsByTagName("button")); mshtml.IHTMLElement coll_id_start_explorer = (mshtml.IHTMLElement)(doc.getElementById("id_start_explorer")); mshtml.IHTMLElement coll_id_start_dialog = (mshtml.IHTMLElement)(doc.getElementById("id_start_dialog")); // https://codevomit.wordpress.com/2015/06/15/wpf-webbrowser-control-part-2/ /* * foreach (mshtml.IHTMLElement obj in coll) * { * HTMLButtonElementEvents_Event htmlButtonEvent = obj as HTMLButtonElementEvents_Event; * htmlButtonEvent.onclick += clickElementHandler; * } * //*/ if (coll_id_start_dialog != null) { HTMLButtonElementEvents_Event htmlButtonEvent = coll_id_start_dialog as HTMLButtonElementEvents_Event; htmlButtonEvent.onclick += start_dialog; } if (coll_id_start_explorer != null) { HTMLButtonElementEvents_Event htmlButtonEvent = coll_id_start_explorer as HTMLButtonElementEvents_Event; htmlButtonEvent.onclick += start_explorer; } }
//获取编辑框已打开 private bool hascommentOpened(mshtml.IHTMLElement commentTag) { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement element1 = (mshtml.IHTMLElement)cusers.Current; if (element1.className == "comment-box-wrap") { return(true); } } return(false); } } } return(false); }
static public IHTMLElement GetFrame(mshtml.IHTMLDocument2 doc) { IHTMLElement frame = null; mshtml.IHTMLWindow2 window2 = null; try { window2 = doc.parentWindow as mshtml.IHTMLWindow2; if (window2 != null) { return(((mshtml.HTMLWindow2)window2).frameElement as IHTMLElement); } } catch (UnauthorizedAccessException) { //主页面和IFRAME页面处于不同域名的时候会报UnauthorizedAccessException,下面通过IHTMLWindow2->IWebBrowser2 //比较IWebBrowser2和iframe元素url定位iframe SHDocVw.IWebBrowser2 browser = CrossFrameIE.GetIWebBrowser2(window2); mshtml.IHTMLDocument3 parentDoc = browser.Parent as mshtml.IHTMLDocument3; mshtml.IHTMLElementCollection framesCollection = parentDoc.getElementsByTagName("iframe") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement f in framesCollection) { SHDocVw.IWebBrowser2 wb2 = (SHDocVw.IWebBrowser2)((mshtml.HTMLFrameElement)f); if (wb2.LocationURL == browser.LocationURL) { frame = f as IHTMLElement; break; } } } catch (Exception) { return(null); } return(frame); }
private void PraiseFriend() { try { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("a"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (element.className == "item qz_like_btn_v3") { if (element.innerText != null && !element.innerText.Contains("取消赞")) { element.click(); praisedMap.Add(curQQ); break; } } } } } catch (Exception) { } }
void Login_Closed(object sender, EventArgs e) { SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); IntPtr handle = GetForegroundWindow(); foreach (SHDocVw.WebBrowser IE in shellWindows) { if (IE.HWND.Equals(handle.ToInt32())) { doc = IE.Document as mshtml.HTMLDocument; } } if (doc != null) { // Document 속성 읽기 Uri uri = new Uri(doc.url); String host = uri.Host; if (host.Contains(naver) || host.Contains(nid_naver)) { mshtml.IHTMLElementCollection elemColl = null; elemColl = doc.getElementsByTagName("input") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement elem in elemColl) { if (elem.getAttribute("id") != null) { if (elem.id == "id") { elem.setAttribute("value", login_ID); } else if (elem.id == "pw") { elem.setAttribute("value", login_PW); } } else if (elem.getAttribute("title") != null) { if (elem.title == "로그인") { elem.click(); } } } }/* * else if (host.Contains(daum) || host.Contains(google)) * { * IHTMLElement q = doc.getElementsByName("q").item("q", 0); * q.setAttribute("value", Clipboard.GetText()); * * IHTMLFormElement form_google = doc.forms.item(Type.Missing, 0); * form_google.submit(); * }*/ else { System.Windows.MessageBox.Show("naver google daum 쓰세요"); } isLogin = false; } }
/// <summary> /// Loads the anchors for a specified html file /// </summary> /// <param name="fileName">The file name in which anchors are to be retrieved from</param> private void LoadAnchors(string fileName) { WebClient client = new WebClient(); byte[] data = client.DownloadData(fileName); mshtml.HTMLDocumentClass ms = new mshtml.HTMLDocumentClass(); string strHTML = Encoding.ASCII.GetString(data); mshtml.IHTMLDocument2 mydoc = (mshtml.IHTMLDocument2)ms; //mydoc.write(!--saved from url=(0014)about:internet -->); mydoc.write(strHTML); mshtml.IHTMLElementCollection ec = (mshtml.IHTMLElementCollection)mydoc.all.tags("a"); if (ec != null) { for (int i = 0; i < ec.length - 1; i++) { mshtml.HTMLAnchorElementClass anchor; anchor = (mshtml.HTMLAnchorElementClass)ec.item(i, 0); if (!string.IsNullOrEmpty(anchor.name)) { cmbAnchor.Items.Add(anchor.name); } } } }
//空间动态里的好友 private void button9_Click(object sender, EventArgs e) { string info = ""; mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); for (int j = 0; j < frame.frames.length; ++j) { try { object rj = j; mshtml.IHTMLWindow2 frameWindow2 = frame.frames.item(ref rj) as mshtml.IHTMLWindow2; IHTMLDocument2 frame2 = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow2); mshtml.IHTMLElementCollection userlist = (mshtml.IHTMLElementCollection)frame2.all.tags("div"); IEnumerator users = userlist.GetEnumerator(); while (users.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)users.Current; if (element.className == "user-list" || element.className == "ui-avatar") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.children; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement celement = (mshtml.IHTMLElement)cusers.Current; string href = (string)celement.getAttribute("href", 0); if (href.Contains("http:")) { info += href + "\n"; } } } } } catch (Exception) { } } } MessageBox.Show(info); }
//3.提交 private bool commentStep3ex(mshtml.IHTMLElement commentTag) { if (commentTag == null) { return(false); } mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement element2 = (mshtml.IHTMLElement)cusers.Current; if (element2.className == "btn-post gb_bt evt_click") { element2.click(); return(true); // mshtml.IHTMLElementCollection element2Col = (mshtml.IHTMLElementCollection)element2.all; // IEnumerator element2Cols = element2Col.GetEnumerator(); // while (element2Cols.MoveNext()) // { // mshtml.IHTMLElement element3 = (mshtml.IHTMLElement)element2Cols.Current; // if (element3.className == "btn-post gb_bt evt_click") // { // element3.click(); // return commentTag; // } // } } } } } } return(false); }
public static mshtml.IHTMLElement GetButtonElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr) { mshtml.IHTMLElement element = null; ElementTag iD = ElementTag.ID; int num = 0; int num2 = 0; if ((indexStr != string.Empty) && (indexStr != "")) { num2 = WindowUtil.StringToInt(indexStr); } if ((tagStr != string.Empty) && (tagStr != "")) { iD = (ElementTag)WindowUtil.StringToInt(tagStr); } mshtml.IHTMLElementCollection o = (mshtml.IHTMLElementCollection)doc.all.tags("input"); foreach (mshtml.IHTMLElement element2 in o) { if ((IsElementMatchType(element2, "submit") || IsElementMatchType(element2, "button")) && IsElementMatch(element2, iD, itemName, "")) { if (num == num2) { element = element2; break; } num++; } } if (o != null) { Marshal.ReleaseComObject(o); } o = (mshtml.IHTMLElementCollection)doc.all.tags("button"); foreach (mshtml.IHTMLElement element3 in o) { if (IsElementMatch(element3, iD, itemName, "")) { if (num == num2) { return(element3); } num++; } } return(element); }
//检测是否已评论 private mshtml.IHTMLElement gerCommented() { String myqq = getMyQQ(); mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); bool cangonext = true; while (cusers.MoveNext()) { mshtml.IHTMLElement celement = (mshtml.IHTMLElement)cusers.Current; Console.WriteLine(celement.className); if (celement.className == "comments-item bor3") { if ((String)celement.getAttribute("data-uin", 0) == myqq) { cangonext = false; break; } } } //1.打开编辑框 if (cangonext)//自己没有评论 { return(element); } } } } return(null); }
//获取最后活跃时间 private void button12_Click(object sender, EventArgs e) { string info = null; mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); for (int j = 0; j < frame.frames.length; ++j) { object rj = j; mshtml.IHTMLWindow2 frameWindow2 = frame.frames.item(ref rj) as mshtml.IHTMLWindow2; IHTMLDocument2 frame2 = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow2); mshtml.IHTMLElementCollection userlist = (mshtml.IHTMLElementCollection)frame2.all.tags("span"); IEnumerator users = userlist.GetEnumerator(); while (users.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)users.Current; string str = element.innerText; if (str != null && str.Contains("月") && str.Contains("日") && str.Contains(":")) { info = str; break; } } if (info != null) { break; } } if (info != null) { break; } } MessageBox.Show(info); }
//切换到账号输入 private void button4_Click(object sender, EventArgs e) { try { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; object index = 0; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection logins = (mshtml.IHTMLElementCollection)frame.all.tags("a"); mshtml.IHTMLElement element = (mshtml.IHTMLElement)logins.item("switcher_plogin", 0); element.click(); } catch (System.Exception _e) { Console.Write(_e.Message); } }
//检测是否评论成功 private bool isCommentedSucc() { if (commentTag == null) { return(false); } String myqq = Func.getMyQQ(webBrowser1); mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement element2 = (mshtml.IHTMLElement)cusers.Current; if (element2.className == "comments-item bor3") { if (element2.innerHTML.Contains(myqq)) { return(true); } } } } } } return(false); }
//2.编辑 private mshtml.IHTMLElement commentStep2(mshtml.IHTMLElement commentTag) { if (commentTag == null) { return(null); } mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||"); while (cusers.MoveNext()) { mshtml.IHTMLElement element2 = (mshtml.IHTMLElement)cusers.Current; Console.WriteLine(element2.className); if (element2.className == "textinput textarea c_tx2") { element2.innerText = "哈哈:" + Environment.TickCount; return(element); } } Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$"); } } } return(null); }
private void Stop_Play_Click(object sender, RoutedEventArgs e) { playOn = !playOn; if (playOn) { Stop_Play.Content = FindResource("Play"); } else { Stop_Play.Content = FindResource("Stop"); } SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); IntPtr handle = GetForegroundWindow(); foreach (SHDocVw.WebBrowser IE in shellWindows) { if (IE.HWND.Equals(handle.ToInt32())) { doc = IE.Document as mshtml.HTMLDocument; } } if (doc != null) { mshtml.IHTMLElementCollection elemColl = null; elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement elem in elemColl) { if (elem.getAttribute("class") != null) { if (elem.className == "ytp-play-button ytp-button") { elem.click(); break; } } } } }
private void InspectFrameMouseEvent(mshtml.IHTMLElementCollection fc) { if (fc == null) { return; } if (fc.length > 0) { for (int i = 0; i < fc.length; i++) { object id = (object)i; IHTMLWindow2 frameWindow = (IHTMLWindow2)fc.item(id, 0); mshtml.HTMLDocument frameDoc = (mshtml.HTMLDocument)frameWindow.document; mshtml.DispHTMLDocument frameDispDoc = (mshtml.DispHTMLDocument)frameDoc; DHTMLEventHandler onmousedownhand = new DHTMLEventHandler(frameDoc); onmousedownhand.Handler += new DHTMLEvent(Mouse_Down); frameDispDoc.onmousedown = onmousedownhand; IHTMLElementCollection col = BrowserExtensions.GetFrames((IHTMLDocument2)frameDoc); InspectFrameMouseEvent(col); } } }
private void PraiseFriendFix() { try { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("A"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (element.className == "qz_like_btn c_tx mr8") { string style = (string)element.style.cssText; if (element.innerText != null && element.innerText.Contains("取消赞") && style != "display: none;") { element.click(); success.Add(curQQ); richTextBox1.Text = richTextBox1.Text + "【成功】" + curQQ + "\n"; return; } } } } } catch (Exception) { } failed.Add(curQQ); richTextBox1.Text = richTextBox1.Text + "【失败】" + curQQ + "\n"; }
//3.提交 private mshtml.IHTMLElement commentStep3(mshtml.IHTMLElement commentTag) { if (commentTag == null) { return(null); } mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("a"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { try { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (element.className == "btn-post gb_bt evt_click" && element.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement == commentTag) { element.click(); CommentMap.Add(curQQ); return(commentTag); } } catch (Exception ex) { Console.WriteLine("*********************************************************"); Console.WriteLine(ex.ToString()); Console.WriteLine("*********************************************************"); } } } return(null); }
//获取【说说】的好友信息 private void button7_Click(object sender, EventArgs e) { string info = null; mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection divs = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator div = divs.GetEnumerator(); while (div.MoveNext()) { mshtml.IHTMLElement item = (mshtml.IHTMLElement)div.Current; if (item.className == "ui_avatar" || item.className == "feed_like") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)item.children; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement celement = (mshtml.IHTMLElement)cusers.Current; if (celement.tagName == "a" || celement.tagName == "A") { string href = (string)celement.getAttribute("href", 0); if (href != null && href.Contains("http:")) { info += href + "\n"; } } } } } } MessageBox.Show(info); }
//2.编辑 private bool commentStep2(mshtml.IHTMLElement commentTag) { if (commentTag == null) { return(false); } mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement element2 = (mshtml.IHTMLElement)cusers.Current; if (element2.className == "textinput textarea c_tx2" || element2.className == "textinput textarea c_tx2 input_focus textinput_focus") //if (element2.className == "textinput textarea c_tx2 input_focus textinput_focus") { element2.innerText = getReplyStr(); return(true); } } } } } return(false); }
//获取最后活跃时间 private void getLasTime() { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); for (int j = 0; j < frame.frames.length; ++j) { object rj = j; mshtml.IHTMLWindow2 frameWindow2 = frame.frames.item(ref rj) as mshtml.IHTMLWindow2; IHTMLDocument2 frame2 = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow2); mshtml.IHTMLElementCollection userlist = (mshtml.IHTMLElementCollection)frame2.all.tags("span"); IEnumerator users = userlist.GetEnumerator(); while (users.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)users.Current; string str = element.innerText; if (str != null && str.Contains("月") && str.Contains("日") && str.Contains(":")) { DateTime dnow = DateTime.Now; str = str.Replace("月", "-"); str = str.Replace("日", "-"); str = str.Replace(" ", ""); str = str.Replace(":", "-"); str = String.Format("{0}-{1}-00", dnow.Year, str); spider.UIDB.logintime = str; return; } } } } }
//输入账号密码 private void button5_Click(object sender, EventArgs e) { try { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; object index = 0; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection logins = (mshtml.IHTMLElementCollection)frame.all.tags("input"); mshtml.IHTMLInputElement element = (mshtml.IHTMLInputElement)logins.item("u", 0); element.value = "305723370"; element = (mshtml.IHTMLInputElement)logins.item("p", 0); element.value = "cdtanji51520"; } catch (System.Exception _e) { Console.Write(_e.Message); } }
//1.打开编辑框 private mshtml.IHTMLElement commentStep1(mshtml.IHTMLElement commentTag) { String myqq = getMyQQ(); mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("div"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (commentTag == element && element.className == "mod-comments") { mshtml.IHTMLElementCollection childrenCol = (mshtml.IHTMLElementCollection)element.all; IEnumerator cusers = childrenCol.GetEnumerator(); while (cusers.MoveNext()) { mshtml.IHTMLElement element1 = (mshtml.IHTMLElement)cusers.Current; //if (element1.className == "textinput textinput-default bor2") if (element1.className == "mod-commnets-poster feedClickCmd comment_default_inputentry") { element1.click(); return(element); } } } } } return(null); }
public void InjectJavascript(HTMLDocument document) { string script = "window.guideMe = {userKey:'" + USERKEY + "', trackingId:''};"; string url = JSPATH; if (document != null) { mshtml.IHTMLElementCollection headElementCollection = document.getElementsByTagName("head"); if (headElementCollection != null) { mshtml.IHTMLElement injectedScript = document.getElementById("__guideme_script"); if (injectedScript == null) { mshtml.IHTMLElement headElement = headElementCollection.item(0, 0) as mshtml.IHTMLElement; mshtml.IHTMLElement guideme = (mshtml.IHTMLElement)document.createElement("script"); mshtml.IHTMLScriptElement guidemeScript = (mshtml.IHTMLScriptElement)guideme; guidemeScript.text = script; mshtml.IHTMLDOMNode guidemeNode = (mshtml.IHTMLDOMNode)guideme; guideme.id = "__guideme_script_config"; mshtml.IHTMLElement element = (mshtml.IHTMLElement)document.createElement("script"); mshtml.IHTMLScriptElement scriptElement = (mshtml.IHTMLScriptElement)element; scriptElement.src = url; element.id = "__guideme_script"; mshtml.IHTMLDOMNode node = (mshtml.IHTMLDOMNode)element; mshtml.HTMLBody body = document.body as mshtml.HTMLBody; body.appendChild(guidemeNode); body.appendChild(node); } Marshal.ReleaseComObject(document); } } }
private void PraiseFriend() { try { mshtml.HTMLDocumentClass htmlDoc = webBrowser1.Document.DomDocument as mshtml.HTMLDocumentClass; for (int i = 0; i < htmlDoc.frames.length; ++i) { object index = i; mshtml.IHTMLWindow2 frameWindow = htmlDoc.frames.item(ref index) as mshtml.IHTMLWindow2; IHTMLDocument2 frame = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(frameWindow); mshtml.IHTMLElementCollection tagls = (mshtml.IHTMLElementCollection)frame.all.tags("A"); IEnumerator tagie = tagls.GetEnumerator(); while (tagie.MoveNext()) { mshtml.IHTMLElement element = (mshtml.IHTMLElement)tagie.Current; if (element.className == "qz_like_btn c_tx mr8") { if (element.innerText != null && !element.innerText.Contains("取消赞")) { element.click(); pro = "点赞完成"; //richTextBox1.Text = richTextBox1.Text + "【成功】" + curQQ + "\n"; return; } } } } } catch (Exception) { } //richTextBox1.Text = richTextBox1.Text + "【失败】" + curQQ + "\n"; Zhan();//失败后直接进入下一个 }
// search input complete void Keyboard_Closed(object sender, EventArgs e) { SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); IntPtr handle = GetForegroundWindow(); foreach (SHDocVw.WebBrowser IE in shellWindows) { if (IE.HWND.Equals(handle.ToInt32())) { doc = IE.Document as mshtml.HTMLDocument; } } if (doc != null) { // Document 속성 읽기 Uri uri = new Uri(doc.url); String host = uri.Host; if (host.Contains(naver)) { //검색어 셋팅 IHTMLElement query = doc.getElementsByName("query").item("query", 0); query.setAttribute("value", System.Windows.Clipboard.GetText()); //네이버검색버튼 : search_btn doc.getElementById("search_btn").click(); } else if (host.Contains(search_naver)) { mshtml.IHTMLElementCollection elemColl = null; elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection; foreach (mshtml.IHTMLElement elem in elemColl) { if (elem.getAttribute("class") != null) { if (elem.className == "bt_search spim") { IHTMLElement query = doc.getElementsByName("query").item("query", 0); //검색어 셋팅 query.setAttribute("value", System.Windows.Clipboard.GetText()); elem.click(); break; } } } } else if (host.Contains(daum) || host.Contains(google)) { IHTMLElement q = doc.getElementsByName("q").item("q", 0); q.setAttribute("value", System.Windows.Clipboard.GetText()); IHTMLFormElement form_google = doc.forms.item(Type.Missing, 0); form_google.submit(); } else { System.Windows.MessageBox.Show("naver google daum 쓰세요"); } } }
public static mshtml.IHTMLElement GetRadioElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr) { mshtml.IHTMLElementCollection o = (mshtml.IHTMLElementCollection)doc.all.tags("input"); mshtml.IHTMLElement element = null; ElementTag iD = ElementTag.ID; bool flag = false; int num = 0; int num2 = 0; if (!string.IsNullOrEmpty(tagStr)) { iD = (ElementTag)WindowUtil.StringToInt(tagStr); } if (!string.IsNullOrEmpty(indexStr)) { num = WindowUtil.StringToInt(indexStr); } foreach (mshtml.IHTMLElement element2 in o) { if (IsElementMatchType(element2, "radio") && IsElementMatch(element2, iD, itemName, "")) { if (num == num2) { element = element2; flag = true; break; } num2++; } } if (o != null) { Marshal.ReleaseComObject(o); } if (!flag) { o = (mshtml.IHTMLElementCollection)doc.all.tags("label"); foreach (mshtml.IHTMLElement element3 in o) { if (element3.getAttribute("htmlFor", 0) != null) { string str = element3.getAttribute("htmlFor", 0).ToString(); if (!string.IsNullOrEmpty(str)) { mshtml.IHTMLElement ele = doc.all.item(str, Missing.Value) as mshtml.IHTMLElement; if (((ele != null) && IsElementMatchType(ele, "radio")) && IsElementMatch(element3, iD, itemName, "")) { if (num == num2) { element = element3; flag = true; break; } num2++; } } } } } if (o != null) { Marshal.ReleaseComObject(o); } return(element); }
bool LR_click(IHTMLEventObj pEvtObj) { IHTMLElement gg = pEvtObj.srcElement; feed_id = gg.getAttribute("feedid"); string feed_link = gg.getAttribute("feedlink"); mshtml.IHTMLElementCollection feed_div = document.getElementById(feed_id).all; foreach (mshtml.IHTMLElement elem1 in feed_div) { // bejárja a címsor(lista) if (Conf.cimsor_class.Contains(elem1.className)) { foreach (IHTMLElement cim_elem in elem1.all) { if (Conf.cimsor_elem_class.Contains(cim_elem.className)) { cim_elemek.Add(cim_elem.innerText); } } } else if (Conf.intro_class.Contains(elem1.className)) { intro = elem1.innerHTML; } else if (Conf.user_ikon_class.Contains(elem1.className)) { user_ikon_sourci = elem1.getAttribute("src"); } else if (Conf.feed_image_class.Contains(elem1.className)) { feed_image_sourci = elem1.getAttribute("src"); } else if (Conf.feed_image_szoveg_class.Contains(elem1.className)) { feed_image_szoveg = elem1.innerHTML; } } int i = 1; IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)document.body).createControlRange(); foreach (mshtml.IHTMLImgElement img in doc.images) { string sourci = img.src; // if (sourci == user_ikon_sourci || sourci == feed_image_sourci) { Bitmap ujkep = GetImage(img); ujkep.Save(@"d:\Temp\hh" + i + ".jpg"); byte[] bite = BitmapToArray(ujkep); string base64String = Convert.ToBase64String(bite); string URI = "http://like.infolapok.hu"; string myParameters = "param1=value1¶m2=value2¶m3=" + base64String; using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; string HtmlResult = wc.UploadString(URI, myParameters); Console.WriteLine(" a válasz: {0}", HtmlResult); } // string ff= Encoding.ASCII.GetString(responseArray); i++; } } bool kk = true; return(kk); }