public void displayContextual() { string keyword = "dog"; string link = "http://ass.com"; // temp. replace all links with something else foreach (IHTMLElement tempElement in document.getElementsByTagName("a")) { string tempstr = tempElement.getAttribute("href").ToString(); tempElement.setAttribute("href", tempstr.Replace(keyword, "doxxxg")); } // now replace all keywords with links foreach (IHTMLElement tempElement in document.getElementsByTagName("div")) { tempElement.innerHTML = tempElement.innerHTML.Replace(keyword, "<a href=\"http://misterevil.com\">dog</a>"); } // now revert back to orig. link int icount = 0; foreach (IHTMLElement tempElement in document.getElementsByTagName("a")) { tempElement.setAttribute("href", tempElement.getAttribute("href").ToString().Replace("doxxxg", keyword)); tempElement.onmouseover = "document.getElementById('adz" + icount.ToString() + "').style.display='';"; tempElement.onmouseout = "document.getElementById('adz" + icount.ToString() + "').style.display='none';"; string ad = "<div id=\"adz" + icount.ToString() + "\" style=\"display: none; border:1px solid #000; color: blue;\"><a href=\"" + link + "\">Click this Shit! It's really f*****g awesome! I'm not even s******g you!</a></div>"; tempElement.insertAdjacentHTML("beforeBegin", ad); icount++; } }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { HtmlDocument document = browser.Document; HtmlElement head = document.GetElementsByTagName("head")[0]; HTMLDocument mshtml = (HTMLDocument)document.DomDocument; IHTMLDOMNode msHead = null; foreach (IHTMLDOMNode item in mshtml.getElementsByTagName("head")) { msHead = item; } List <IHTMLDOMNode> origins = new List <IHTMLDOMNode>(); foreach (IHTMLDOMNode item in msHead.childNodes) { origins.Add(item); msHead.removeChild(item); } IHTMLStyleSheet sytle = mshtml.createStyleSheet(); sytle.cssText = Style; HtmlElement jquery = document.CreateElement("script"); ((IHTMLScriptElement)jquery.DomElement).text = Resources.jquery; HtmlElement script = document.CreateElement("script"); ((IHTMLScriptElement)script.DomElement).text = Script; head.AppendChild(jquery); head.AppendChild(script); foreach (IHTMLDOMNode item in origins) { msHead.appendChild(item); } UpdateTable(); }
public void LR_sav() { string feedlink = "nincs"; foreach (HTMLDivElement div in document.getElementsByTagName("div")) { //if (div.id == feed_div_id_19.Substring(0, 18)) if (Conf.feed_div_class.Contains(div.className)) { string feed_div_id = div.getAttribute("ID"); foreach (IHTMLElement link1 in div.getElementsByTagName("a")) { if (link1.className == "_5pcq") { feedlink = link1.getAttribute("href"); } } foreach (HTMLDivElement fff in div.getElementsByTagName("div")) { if (Conf.cel_div_class.Contains(fff.className)) { string likediv = "<div class=\"robi\" feedid=\"" + feed_div_id + "\" feedlink=\"" + feedlink + "\" style=\" margin:5px;padding:5px;color:red;background-color:blue;\" >like</div>"; fff.innerHTML = likediv; HTMLElementEvents2_Event iEvent; iEvent = (HTMLElementEvents2_Event)fff; iEvent.onclick += new HTMLElementEvents2_onclickEventHandler(LR_click); // LR Lrobi = new LR(document ); } // Lrobi.aktival(); } } } }
protected override void PastePaymentInfo(PaymentRequest request) { HTMLDocument doc = request.Document; PaymentInfo info = request.PaymentInfo; if (info.IsDefinedTransfer == false) { IEnumerator e = doc.getElementsByTagName("input").GetEnumerator(); while (e.MoveNext()) { IHTMLInputElement input = e.Current as IHTMLInputElement; if ("AccountNumberFullDestinationInput".Equals((e.Current as IHTMLInputElement).value)) { (e.Current as IHTMLElement).click(); break; } } Util.SetElementValue(doc.getElementById(ACCOUNT_FIELD), info.BankAccountNo); Util.SetElementValue(doc.getElementById(NAME_FIELD), ReplaceSpecialChars(info.BillerName)); Util.SetElementValue(doc.getElementById(ADDRESS_FIELD), ReplaceSpecialChars(info.Street)); Util.SetElementValue(doc.getElementById(POSTAL_CODE_FIELD), ReplaceSpecialChars(info.PostalCodeAndCity)); } Util.SetElementValue(doc.getElementById(DESCRIPTION_FIELD), ReplaceSpecialChars(info.Title)); Util.SetElementValue(doc.getElementsByName(AMOUNT_INT_FIELD), info.AmountToPayDecimal); Util.SetElementValue(doc.getElementsByName(AMOUNT_DEC_FIELD), info.AmountToPayFloating); // real value is taken from hidden field Util.SetElementValue(doc.getElementById(AMOUNT_FIELD), info.AmountToPay.Replace(".", ",")); Util.SetElementValue(doc.getElementsByName(YEAR_FIELD), info.DueDateTimeToPaste.Year.ToString()); Util.SetElementValue(doc.getElementsByName(MONTH_FIELD), Util.GetMonth(info.DueDateTimeToPaste.Month)); Util.SetElementValue(doc.getElementsByName(DAY_FIELD), info.DueDateTimeToPaste.Day.ToString()); info.State = State.IN_PROGRESS; }
private int FindFirstVisibleParagraphLine() { var allPara = _htmlDocument.getElementsByTagName("p"); if (allPara == null) { return(-1); } for (var i = 0; i < allPara.length; i++) { var e = allPara.item(i) as IHTMLElement; if (e == null || e.offsetTop >= _viewRect.Bottom) { break; } var center = e.offsetTop + e.offsetHeight / 2; if (center >= _viewRect.Top) { var id = e.id; if (id != null && id.StartsWithOrdinal(_linePragmaPrefix)) { return(int.TryParse(id.Substring(_linePragmaPrefix.Length), out int value) ? value : -1); } } } return(-1); }
private void Check1(object url) { string SourceUrl = (string)url; string HtmlText = GetPageResource(SourceUrl, true); Uri myUri = new Uri(SourceUrl); // System.Windows.Forms.WebBrowser b = new System.Windows.Forms.WebBrowser(); try { web1.Navigate(myUri); HTMLDocument htmlDoc = (HTMLDocument)web1.Document; IHTMLElementCollection htmlElementCollection = htmlDoc.getElementsByTagName("form"); //Set All Anchore Target As _self For Stop Opening New Window...... foreach (IHTMLElement curElement in htmlElementCollection) { // string targetAtt = curElement.getAttribute("target"); System.Console.WriteLine(curElement); } if (HtmlText == "NOTHING!!" || HtmlText == null) { Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { lableSingle.Content = "Detection is complete"; })); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { textBoxSingle.IsEnabled = true; })); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { Button_Check.IsEnabled = true; })); return; } } catch (Exception ex) { } return; }
public void web1_LoadCompleted(object sender, NavigationEventArgs e) { HTMLDocument document = (HTMLDocument)web1.Document; // document.body.innerHTML = "hsfbashfbs"; foreach (IHTMLSpanElement myelem in document.getElementsByTagName("span")) { HTMLSpanElement el = myelem as HTMLSpanElement; if (el.className.Equals("_2dpb")) { el.innerText = "Nyuszóka párja"; // MessageBoxResult messageBoxResult3 = System.Windows.MessageBox.Show("Are youbbbbb sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); // if (messageBoxResult3 == MessageBoxResult.Yes) ; } // HTMLElementCollection elems = web1.Document.Equals; } }
public void divtext(object sender, RoutedEventArgs e) { string lll = ""; HTMLDocument document = (HTMLDocument)web1.Document; foreach (IHTMLElement div in document.getElementsByTagName("div")) { if (div.className == "userContentWrapper _5pcr _3ccb") { IHTMLElementCollection bejar = div.all; IHTMLElementCollection elem = div.all; foreach (IHTMLElement fff in elem) { if (fff.className == "_5pcq") { lll = fff.getAttribute("href"); } if (fff.className == "_5pcp _5vsi _52i6 _1tsu _4l4" || fff.className == "_5pcp _5vsi _52i6 _4l4") { fff.innerHTML = "<div class=\"robi\">like Robi<div>"; } } } } }
/*********************************************************************************************************/ #endregion public void OnDucumentComplete(object pDisp, ref object URL) { this.Debug_config = util.getFilename("debug_config"); /*初始化:读取Debug_Msg 配置是否==‘开’*/ /**日志**/ this.methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; //程序执行位置代码块的方法名 this.msg = methodName + "进入此方法!"; /***/ util.log_to(this.Debug_config, this.methodName, this.msg); /**日志**/ try { document = (HTMLDocument)webBrowser.Document; foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { if (((IHTMLElement)tempElement).id != null && ((IHTMLElement)tempElement).id == "su") { /**日志**/ this.msg = methodName + " baidu_id=" + ((IHTMLElement)tempElement).id; util.log_to(this.Debug_config, this.methodName, this.msg); /**日志**/ ((IHTMLElement)tempElement).setAttribute("value", "我叫周露 -" + this.Debug_config); } //System.Windows.Forms.MessageBox.Show(tempElement.name != null ? tempElement.name : "it sucks, no name, try id=" + ((IHTMLElement)tempElement).id ); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
private void InjectDisableScript() { HTMLDocument doc = LocationWidget.GoogleMap.Document as HTMLDocument; HTMLDocument doc2 = LocationWidget.GoogleMap.Document as HTMLDocument; //Questo crea lo script per la soprressione degli errori IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)doc2.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = DisableScriptError; IHTMLElementCollection nodes = doc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { //Appendo lo script all'head cosi è attivo HTMLHeadElement head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); } }
private void InjectScriptToHead(HTMLDocument doc, string script) { IHTMLDOMNode head = (IHTMLDOMNode)doc.getElementsByTagName("head").item(0); IHTMLScriptElement scriptEl = (IHTMLScriptElement)doc.createElement("script"); scriptEl.type = "text/javascript"; scriptEl.text = script; head.appendChild((IHTMLDOMNode)scriptEl); }
private IHTMLElement GetElementByValueOnce(string tagName, string attName, string attValue) { HTMLDocument document = ((HTMLDocument)IE.Document); IHTMLElement el = null; IHTMLElementCollection tags = document.getElementsByTagName(tagName); IEnumerator enumerator = tags.GetEnumerator(); while (enumerator.MoveNext()) { IHTMLElement element = (IHTMLElement)enumerator.Current; if (element.getAttribute(attName, 0).ToString().Contains(attValue)) { return(element); } } if (el == null) { IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)document.frames; try { object o = null; for (int i = 0; i < frames.length; i++) { o = i; IHTMLWindow2 fr = (IHTMLWindow2)frames.item(ref o); HTMLDocument doc = (HTMLDocument)fr.document; tags = doc.getElementsByTagName(tagName); enumerator = tags.GetEnumerator(); while (enumerator.MoveNext()) { IHTMLElement element = (IHTMLElement)enumerator.Current; bool go = false; try { go = element.getAttribute(attName, 0).ToString().Contains(attValue); } catch { } if (go) { return(element); } } } } catch (Exception ex) { string x = ex.Message; } } return(null); }
public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancle) { document = (HTMLDocument)webBrowser.Document; foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { if (tempElement.type.ToLower() == "password") { System.Windows.Forms.MessageBox.Show(tempElement.value); } } }
public void OnDocumentComplete(object pDisp, ref object URL) { document = (HTMLDocument)webBrowser.Document; foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { System.Windows.Forms.MessageBox.Show( tempElement.name != null?tempElement.name:"it sucks, no name, try id" + ((IHTMLElement)tempElement).id ); } }
private void NavigateIE(string url, string title) { try { if (_loginBrowser != null) { if (!isCaseIDOpened) { _logger.Trace("Going to take the document from the control."); HTMLDocument htmlDoc = (HTMLDocument)_loginBrowser.Document; _logger.Trace("The document retrieved from the control."); var scriptErrorSuppressed = (IHTMLScriptElement)htmlDoc.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = "var caseIdWindow=null; function OpenCaseIdWindow(url,title){ if(caseIdWindow==null){caseIdWindow=window.open(url,title,\"location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes\");} else{caseIdWindow.location=url;} }"; scriptErrorSuppressed.text += "OpenCaseIdWindow('" + url + "','" + title + "')"; IHTMLElementCollection nodes = htmlDoc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { var head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); break; } } else { _logger.Trace("Going to take the document from the control."); HTMLDocument htmlDoc = (HTMLDocument)_loginBrowser.Document; _logger.Trace("The document retrieved from the control."); var scriptErrorSuppressed = (IHTMLScriptElement)htmlDoc.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text += "OpenCaseIdWindow('" + url + "','" + title + "')"; IHTMLElementCollection nodes = htmlDoc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { var head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); break; } } } else { _logger.Trace("The browser window is null."); } } catch (Exception generalException) { _logger.Error("Error occuured as " + generalException.Message); _logger.Trace("Error Trace: " + generalException.StackTrace); } }
private void WebBrowser_Navigated(object sender, NavigationEventArgs e) { dynamic activeX = this.webBrowser.GetType().InvokeMember("ActiveXInstance", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, this.webBrowser, new object[] { }); activeX.Silent = true; ((SHDocVw.WebBrowser)activeX).NavigateError += MainWindow_NavigateError; HTMLDocument document = (HTMLDocument)webBrowser.Document; IHTMLElement topLinks = document.getElementById("g_ctl00_ctl01_pnlHeader"); var headElements = document.getElementsByTagName("head"); }
private void web1_TargetUpdated(object sender, DataTransferEventArgs e) { HTMLDocument document = (HTMLDocument)web1.Document; foreach (IHTMLElement div in document.getElementsByTagName("div")) { if (div.className == "_5pcp _5vsi") { div.innerHTML = "something" + div.innerHTML; } } }
protected override bool IsDefinedTransfersPage(HTMLDocument doc) { IEnumerator e = doc.getElementsByTagName("div").GetEnumerator(); while (e.MoveNext()) { if (TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower().StartsWith(DOMESTIC_TRANSFER_TEXT)) { return(doc.getElementById(BENEFICIARY_LIST) != null); } } return(false); }
protected override bool IsDefinedTransfersPage(HTMLDocument doc) { IEnumerator e = doc.getElementsByTagName("h1").GetEnumerator(); while (e.MoveNext()) { if ("lista p³atnoœci".Equals(TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower())) { return(true); } } return(false); }
/// <summary> /// Checks if any element's inner HTML with given tag name in the provided HTML document /// equals given text. /// </summary> /// <param name="doc">HTML document</param> /// <param name="tagName">HTML tag name</param> /// <param name="text">text to be found</param> /// <returns>true if any element's inner HTML with given tag name in the provided HTML document /// equals given text, false otherwise</returns> private bool ElementsInnerHtmlEquals(HTMLDocument doc, String tagName, String text) { IEnumerator e = doc.getElementsByTagName(tagName).GetEnumerator(); while (e.MoveNext()) { if (text.Equals((e.Current as IHTMLElement).innerHTML)) { return(true); } } return(false); }
private void InjectDisableScript() { HTMLDocument document = this.LocationWidget.GoogleMap.Document as HTMLDocument; HTMLDocument document2 = this.LocationWidget.GoogleMap.Document as HTMLDocument; IHTMLScriptElement element = (IHTMLScriptElement)document2.createElement("SCRIPT"); element.type = "text/javascript"; element.text = "function noError() {\r\n\r\n return true;\r\n }\r\n window.onerror = noError;"; foreach (IHTMLElement element2 in document.getElementsByTagName("head")) { ((HTMLHeadElement)element2).appendChild((IHTMLDOMNode)element); } }
public List <IeElement> GetElementsByTagName(string value) { var result = new List <IeElement>(); var elements = Document.getElementsByTagName(value); foreach (IHTMLElement element in elements) { result.Add(new IeElement(element)); } return(result); }
public void OnDocumentComplete(object pDisp, ref object URL) { /* * Проверка по адресу */ string url = URL.ToString(); bool matched = false; foreach (Regex reg in regulars) { if (reg.Match(url).Success) { matched = true; break; } } ; if (!matched) { return; } document = (HTMLDocument)webBrowser.Document; /* * скрипт уже подключён */ if (document.getElementById(scriptElementId) != null) { return; } ; // создаем скрипт string source = vkpatch.Properties.Resources.vkpatch.ToString(); HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script"); scriptElement.text = source; scriptElement.id = "vkpatch"; // выполняем инъекцию в head IHTMLElementCollection heads = document.getElementsByTagName("head"); foreach (HTMLHeadElement head in heads) { head.appendChild((IHTMLDOMNode)scriptElement); break; } }
private void InsertScript(HTMLDocument xrmDoc, string script) { IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)xrmDoc.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = script; IHTMLElementCollection nodes = xrmDoc.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { HTMLHeadElement head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); } }
public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) { document = (HTMLDocument)webBrowser.Document; foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { if (tempElement.type.ToLower() == "password") { System.Windows.Forms.MessageBox.Show(tempElement.value); } } }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (webBrowser1.ReadyState == WebBrowserReadyState.Complete) { if (webBrowser1.Url.ToString() == "http://intranet.cougarautomation.net/Timesheet/Timesheet.aspx") { Web_V1 = (SHDocVw.WebBrowser_V1)webBrowser1.ActiveXInstance; timesheet = (HTMLDocument)Web_V1.Document; bookingsTable = (HTMLTable)timesheet.all.item("ContentPlaceHolder1_GridViewSessions", 0); if (bookingsTable != null) { bookingsTableInnerHTML = bookingsTable.innerHTML; } else { bookingsTableInnerHTML = ""; } if (!thisMonth) { var anchorElements = timesheet.getElementsByTagName("a"); foreach (HTMLAnchorElement item in anchorElements) { if (item.title == "Go to the previous month") { item.click(); } } timer1.Start(); } else { HTMLInputElement monthRadioButton = (HTMLInputElement)timesheet.all.item("ContentPlaceHolder1_RadioButtonListSessions_2", 0); monthRadioButton.click(); timer1.Start(); } } } } catch (Exception exception) { MessageBox.Show("Unable to connect to timesheet page, please check your connection"); } }
public bool randVisitOther(HTMLDocument document) { var divCollect = document.getElementsByTagName("div"); HTMLDivElement tbContentDIV = null; foreach (HTMLDivElement el in divCollect) { object divClassAttr = el.getAttribute("className", 0); if (divClassAttr == null) { continue; } string divClassName = (string)divClassAttr.ToString(); if (divClassName == "") { continue; } if (divClassName == "tb-content") { tbContentDIV = el; break; } } if (tbContentDIV == null) { return(false); } var tbContentChildDIV = tbContentDIV.all;//.childNodes; if (tbContentChildDIV == null) { return(false); } IHTMLElementCollection tbContentChildDIVCollect = (IHTMLElementCollection)tbContentChildDIV; HTMLDivElement childDIVNode = (HTMLDivElement)(tbContentChildDIVCollect.item(null, 0)); var itemChildsVar = childDIVNode.children;//.all;//.childNodes;//item box IHTMLElementCollection itemChilds = (IHTMLElementCollection)itemChildsVar; int visitOtherCnt = rndGenerator.Next(1, 3); for (int i = 0; i < visitOtherCnt; i++) //随机货比三家 { int randIndex = rndGenerator.Next(0, itemChilds.length); } return(true); }
protected override bool ReadyToPaste(PaymentRequest request) { HTMLDocument doc = request.Document; bool readyToPaste = false; IEnumerator e = doc.getElementsByTagName("h2").GetEnumerator(); while (e.MoveNext()) { if ("przelew krajowy na rachunek obcy".Equals(TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower())) { readyToPaste = true; } } if (readyToPaste == false) { return(false); } IHTMLElement menuTransfers = doc.getElementById("menu_transfers"); if ("selected".Equals(menuTransfers.className)) { IEnumerator e1 = doc.getElementsByTagName("li").GetEnumerator(); while (e1.MoveNext()) { IHTMLElement element = e1.Current as IHTMLElement; if (TrimHtml(element.innerHTML).ToLower().Contains("dane") && "first-step".Equals(element.className)) { return(true); } } } return(false); }
private HTMLEmbed FindFlashElementRecursive(HTMLDocument document) { var embed = document.getElementsByTagName("embed").OfType <HTMLEmbed>().FirstOrDefault(x => x.src.Contains(".swf?")); if (embed != null) { return(embed); } var frames = document.frames; if (frames == null) { return(null); } int count = frames.length; for (int i = 0; i < count; i++) { var item = frames.item(i); var provider = item as IServiceProvider; if (provider == null) { continue; } object ppvObject; provider.QueryService(typeof(IWebBrowserApp).GUID, typeof(IWebBrowser2).GUID, out ppvObject); var webBrowser = ppvObject as IWebBrowser2; if (webBrowser == null) { continue; } var iframeDocument = webBrowser.Document as HTMLDocument; if (iframeDocument == null) { continue; } embed = FindFlashElementRecursive(iframeDocument); if (embed != null) { return(embed); } } return(null); }
protected override bool IsUserLogged(PaymentRequest request) { HTMLDocument doc = request.Document; if (doc.url.Contains("/centrum24-web")) { IEnumerator e = doc.getElementsByTagName("a").GetEnumerator(); while (e.MoveNext()) { if ("wyloguj".Equals(TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower())) { return(true); } } } return(false); }
private void Navigated(object sender, NavigationEventArgs e) { //Inject error disable script; HTMLDocument dom = (HTMLDocument)_transactionsBrowser.Document; IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)dom.createElement("SCRIPT"); scriptErrorSuppressed.type = "text/javascript"; scriptErrorSuppressed.text = DisableScriptError; IHTMLElementCollection nodes = dom.getElementsByTagName("head"); foreach (IHTMLElement elem in nodes) { HTMLHeadElement head = (HTMLHeadElement)elem; head.appendChild((IHTMLDOMNode)scriptErrorSuppressed); } }
public bool randVisitOther(HTMLDocument document) { var divCollect = document.getElementsByTagName("div"); HTMLDivElement tbContentDIV = null; foreach (HTMLDivElement el in divCollect) { object divClassAttr = el.getAttribute("className", 0); if (divClassAttr == null) { continue; } string divClassName = (string)divClassAttr.ToString(); if (divClassName == "") { continue; } if (divClassName == "tb-content") { tbContentDIV = el; break; } } if (tbContentDIV == null) { return false; } var tbContentChildDIV = tbContentDIV.all;//.childNodes; if (tbContentChildDIV == null) { return false; } IHTMLElementCollection tbContentChildDIVCollect = (IHTMLElementCollection)tbContentChildDIV; HTMLDivElement childDIVNode = (HTMLDivElement)(tbContentChildDIVCollect.item(null, 0)); var itemChildsVar = childDIVNode.children;//.all;//.childNodes;//item box IHTMLElementCollection itemChilds = (IHTMLElementCollection)itemChildsVar; int visitOtherCnt = rndGenerator.Next(1, 3); for (int i = 0; i < visitOtherCnt; i++ )//随机货比三家 { int randIndex = rndGenerator.Next(0, itemChilds.length); } return true; }
/// <summary> /// Handle the DocumentComplete event. /// </summary> /// <param name="pDisp"> /// The pDisp is an an object implemented the interface InternetExplorer. /// By default, this object is the same as the ieInstance, but if the page /// contains many frames, each frame has its own document. /// </param> void IeInstance_DocumentComplete(object pDisp, ref object URL) { if (ieInstance == null) { return; } // get the url string url = URL as string; if (string.IsNullOrEmpty(url) || url.Equals(@"about:Tabs", StringComparison.OrdinalIgnoreCase) || url.Equals("about:blank", StringComparison.OrdinalIgnoreCase)) { return; } // http://borderstylo.com/posts/115-browser-wars-2-dot-0-the-plug-in SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)ieInstance; if (browser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { return; } // Set the handler of the document in InternetExplorer. NativeMethods.ICustomDoc customDoc = (NativeMethods.ICustomDoc)ieInstance.Document; customDoc.SetUIHandler(openImageDocHostUIHandler); // sets the document this.document = (HTMLDocument) ieInstance.Document; try { if (this.document.url.Contains(@"thousandpass") || this.document.url.Contains(@"1000pass.com")) { // Mark the add_on as installed! IHTMLElement div1000pass_add_on = this.document.getElementById("1000pass_add_on"); div1000pass_add_on.className = @"installed"; IHTMLElement div1000pass_add_on_version = this.document.getElementById("1000pass_add_on_version"); div1000pass_add_on_version.innerText = VERSION; // Try to save the token string token = div1000pass_add_on.getAttribute("token").ToString(); if (!String.IsNullOrEmpty(token)) { Utils.WriteToFile(Utils.TokenFileName, token); } foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG")) { if (htmlElement.className == "remote_site_logo") { IHTMLStyle htmlStyle = (IHTMLStyle)htmlElement.style; htmlStyle.cursor = "pointer"; DHTMLEventHandler Handler = new DHTMLEventHandler((IHTMLDocument2)ieInstance.Document); Handler.Handler += new DHTMLEvent(Logo_OnClick); htmlElement.onclick = Handler; htmlElement.setAttribute("alreadyopened", "false", 0); } } } else { // Must run on a thread to guaranty the page has finished loading (js loading) // http://stackoverflow.com/questions/3514945/running-a-javascript-function-in-an-instance-of-internetexplorer System.Threading.ThreadPool.QueueUserWorkItem((o) => { System.Threading.Thread.Sleep(500); try { Thread aThread = new Thread(bind); aThread.SetApartmentState(ApartmentState.STA); aThread.Start(); } catch (Exception ee) { Utils.l(ee); } }, browser); } } catch (Exception e) { Utils.l(e); } }
public void OnDocumentComplete(object pDisp, ref object URL) { document = (HTMLDocument)webBrowser.Document; foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT")) { System.Windows.Forms.MessageBox.Show( tempElement.name != null ? tempElement.name : "it sucks, no name, try id" + ((IHTMLElement)tempElement).id); } }
private HTMLEmbed FindFlashElementRecursive(HTMLDocument document) { var embed = document.getElementsByTagName("embed").OfType<HTMLEmbed>().FirstOrDefault(x => x.src.Contains(".swf?")); if (embed != null) return embed; var frames = document.frames; if (frames == null) return null; int count = frames.length; for (int i = 0; i < count; i++) { var item = frames.item(i); var provider = item as IServiceProvider; if (provider == null) continue; object ppvObject; provider.QueryService(typeof(IWebBrowserApp).GUID, typeof(IWebBrowser2).GUID, out ppvObject); var webBrowser = ppvObject as IWebBrowser2; if (webBrowser == null) continue; var iframeDocument = webBrowser.Document as HTMLDocument; if (iframeDocument == null) continue; embed = FindFlashElementRecursive(iframeDocument); if (embed != null) return embed; } return null; }
IHTMLElement FindElement(string xPath, HTMLDocument doc) { IHTMLElement theElement = null; try { string[] tmp = xPath.Split(new string[] { "##" }, StringSplitOptions.None); string elementAttributes = tmp[1]; string[] attributes = elementAttributes.Split(new string[] { ";" }, StringSplitOptions.None); string attributeId = attributes[0].Replace(@"id=", ""); string attributeName = attributes[1].Replace(@"name=", ""); string attributeClass = attributes[2].Replace(@"class=", ""); string[] xPathParts = tmp[0].Split('/'); string elementTagName = xPathParts[xPathParts.Length - 1]; if (elementTagName.Contains("[")) { elementTagName = elementTagName.Split('[')[0]; } // try in first place the id (if it's unique) theElement = doc.getElementById(attributeId); if (theElement != null && !String.IsNullOrEmpty(attributeId)) { int c = 0; IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName); foreach (IHTMLElement possibleElement in possibleElements) { if (possibleElement.id == attributeId) { c++; } } if (c > 1) { theElement = null; } } if (theElement == null && !String.IsNullOrEmpty(attributeName)) { IHTMLElementCollection possibleElements = doc.getElementsByName(attributeName); if (possibleElements.length == 1) { theElement = (IHTMLElement)possibleElements.item(null, 0); } } // try next, the exact xpath try { if (theElement == null) { IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName); foreach (IHTMLElement possibleElement in possibleElements) { string possibleXPath = ""; try { possibleXPath = Utils.FindXPath(possibleElement); //Utils.l(possibleXPath); } catch (Exception e) { //Utils.l(e); } if (possibleXPath == xPath) { theElement = possibleElement; break; } } } } catch (Exception ex) { Utils.l(ex); } try { // next, try the path skipping attributes if (theElement == null) { string cleanXPath = tmp[0]; IHTMLElementCollection possibleElements = doc.getElementsByTagName(elementTagName); foreach (IHTMLElement possibleElement in possibleElements) { if (possibleElement.tagName == "INPUT") { IHTMLInputElement tmpInput = (IHTMLInputElement)possibleElement; if (tmpInput.type == "hidden" || tmpInput.type == "text" || tmpInput.type == "password") { continue; } } string possibleXPath = Utils.FindXPath(possibleElement); string[] possibleTmp = possibleXPath.Split(new string[] { "##" }, StringSplitOptions.None); string cleanPossibleXPath = possibleTmp[0]; if (cleanPossibleXPath == cleanXPath) { theElement = possibleElement; break; } } } } catch (Exception ee) { Utils.l(ee); } } catch (Exception e) { Utils.l(e); } return theElement; }
public void OnDocumentComplete(object pDisp, ref object URL) { /* * Проверка по адресу */ string url = URL.ToString(); bool matched = false; foreach (Regex reg in regulars) { if (reg.Match(url).Success) { matched = true; break; } }; if (!matched) { return; } document = (HTMLDocument)webBrowser.Document; /* * скрипт уже подключён */ if (document.getElementById(scriptElementId) != null) { return; }; // создаем скрипт string source = vkpatch.Properties.Resources.vkpatch.ToString(); HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script"); scriptElement.text = source; scriptElement.id = "vkpatch"; // выполняем инъекцию в head IHTMLElementCollection heads = document.getElementsByTagName("head"); foreach (HTMLHeadElement head in heads) { head.appendChild((IHTMLDOMNode) scriptElement); break; } }
private IHTMLElementCollection GetElements(string tagName, HTMLDocument doc) { if (tagName == TagName.ALL_TAGS) return doc.all; else return doc.getElementsByTagName(tagName); }
public void loadFiles(XmlNode xn,HTMLDocument document) { try { /*动态加载JavaScript文件 * 需先判断是否已经加载项目;如未加载再加入该模块 * */ XmlNodeList jsFiles = xn.SelectNodes("js"); foreach (XmlNode jsFile in jsFiles) { XmlElement jsxe = (XmlElement)jsFile; if (document.getElementById(jsxe.GetAttribute("keyID")) == null) { IHTMLElement script = document.createElement("script"); script.setAttribute("src", jsxe.InnerText, 0); script.setAttribute("type", "text/javascript", 0); script.setAttribute("defer", jsxe.GetAttribute("defer"), 0); script.setAttribute("id", jsxe.GetAttribute("keyID"), 0); script.setAttribute("charset", "utf-8", 0); IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0); head.appendChild((IHTMLDOMNode)script); } } /*动态加载CSS文件 * 需先判断是否已经加载项目;如未加载再加入该模块 * */ XmlNodeList cssFiles = xn.SelectNodes("css"); foreach (XmlNode cssFile in cssFiles) { XmlElement cssxe = (XmlElement)cssFile; if (document.getElementById(cssxe.GetAttribute("keyID")) == null) { IHTMLElement css = document.createElement("link"); css.setAttribute("rel", "stylesheet", 0); css.setAttribute("type", "text/css", 0); css.setAttribute("href", cssxe.InnerText, 0); css.setAttribute("id", cssxe.GetAttribute("keyID"), 0); IHTMLDOMNode head = (IHTMLDOMNode)document.getElementsByTagName("head").item(0, 0); head.appendChild((IHTMLDOMNode)css); //document.createStyleSheet(cssxe.InnerText, 1);//方法二 } } } catch (Exception e) { //alert(e.Message); throw e; } }