public DocHTML(HTMLDocument doc) { mDoc = doc; mDoc2 = (IHTMLDocument2)mDoc; mDoc3 = (IHTMLDocument3)mDoc; mDoc4 = (IHTMLDocument4)mDoc; mDoc5 = (IHTMLDocument5)mDoc; }
public DocHTML(HTMLDocument doc) { this.mDoc = doc; this.mDoc2 = (IHTMLDocument2)this.mDoc; this.mDoc3 = (IHTMLDocument3)this.mDoc; this.mDoc4 = (IHTMLDocument4)this.mDoc; this.mDoc5 = (IHTMLDocument5)this.mDoc; }
public DocHTML(HTMLDocument doc) { mDoc = doc; mDoc2 = (IHTMLDocument2)mDoc; mDoc3 = (IHTMLDocument3)mDoc; mDoc4 = (IHTMLDocument4)mDoc; mDoc5 = (IHTMLDocument5)mDoc; }
public DocumentAdapter( object document ) { //_documentUri = documentUri; _raw = document; _document = document as IHTMLDocument; _document2 = document as IHTMLDocument2; _document3 = document as IHTMLDocument3; _document4 = document as IHTMLDocument4; _document5 = document as IHTMLDocument5; }
public DocumentAdapter(object document) { //_documentUri = documentUri; _raw = document; _document = document as IHTMLDocument; _document2 = document as IHTMLDocument2; _document3 = document as IHTMLDocument3; _document4 = document as IHTMLDocument4; _document5 = document as IHTMLDocument5; }
private static object getDocumentAttribute(IHTMLDocument2 theHTMLDocument, string theAttributeName) { IHTMLDocument5 doc5 = (IHTMLDocument5)theHTMLDocument; IHTMLDocument3 doc3 = (IHTMLDocument3)theHTMLDocument; //compatibility mode affects how height is computed if ((doc3.documentElement != null) && (!doc5.compatMode.Equals("BackCompat"))) { return(doc3.documentElement.getAttribute(theAttributeName, 0)); } else { return(theHTMLDocument.body.getAttribute(theAttributeName, 0)); } }
//************************************************************ //* Functions of get new donators * //************************************************************ private string GetChatContent() { string HTMLContent = null; try { IntPtr Message = RegisterWindowMessage("WM_HTML_GETOBJECT"); IntPtr MessageTimeOut = SendMessageTimeout(PotPlayer.MainChatRoom, Message); IHTMLDocument5 HTMLDocument = GetHTMLDocument(MessageTimeOut); HTMLContent = ((HTMLDocumentClass)HTMLDocument).body.innerHTML; } catch (Exception e) { File.WriteAllText(@".\GetChatContentError.txt", e.ToString()); } return(HTMLContent); }
public IHTMLDocument5 GetHTMLDocument(IntPtr ChatRoomHandle) { IHTMLDocument5 Result = null; try { Result = (IHTMLDocument5)ObjectFromLresult(ChatRoomHandle, typeof(IHTMLDocument5).GUID, IntPtr.Zero); } catch (COMException) { } catch (InvalidCastException) { return(null); } return(Result); }
private List <IntPtr> Get_PotPlayer_ChatRooms(List <IntPtr> IESs) { List <IntPtr> Result = new List <IntPtr>(); IntPtr Message = IntPtr.Zero; IntPtr MessageTimeOut = IntPtr.Zero; IHTMLDocument5 HTMLDocument = null; string HTMLContent = null; foreach (IntPtr IES in IESs) { Message = RegisterWindowMessage("WM_HTML_GETOBJECT"); MessageTimeOut = SendMessageTimeout(IES, Message); HTMLDocument = GetHTMLDocument(MessageTimeOut); if (HTMLDocument != null && HTMLDocument.GetType().Name == "HTMLDocumentClass" && ((HTMLDocumentClass)HTMLDocument).url.Contains("blank")) { HTMLContent = ((HTMLDocumentClass)HTMLDocument).body.innerHTML; if (HTMLContent != null && HTMLContent.Contains("wrap_chat")) { Result.Add(IES); } } } return(Result); }
/// <summary> /// Private helper method for the constructors /// </summary> /// <param name="document2">IHTMLDocument2</param> /// <param name="contentWindow">WindowDetails</param> private void Init(IHTMLDocument2 document2, WindowDetails contentWindow) { this.document2 = document2; this.contentWindow = contentWindow; this.document3 = document2 as IHTMLDocument3; // Check what access method is needed for the document IHTMLDocument5 document5 = (IHTMLDocument5)document2; //compatibility mode affects how height is computed isDTD = false; try { if ((document3.documentElement != null) && (!document5.compatMode.Equals("BackCompat"))) { isDTD = true; } } catch (Exception ex) { LOG.Error("Error checking the compatibility mode:"); LOG.Error(ex); } Rectangle clientRectangle = contentWindow.WindowRectangle; try { IHTMLWindow2 window2 = (IHTMLWindow2)document2.parentWindow; //IHTMLWindow3 window3 = (IHTMLWindow3)document2.parentWindow; IHTMLScreen2 screen2 = (IHTMLScreen2)window2.screen; IHTMLScreen screen = window2.screen; if (parent != null) { // Copy parent values zoomLevelX = parent.zoomLevelX; zoomLevelY = parent.zoomLevelY; viewportRectangle = parent.viewportRectangle; } else { //DisableScrollbars(document2); // Calculate zoom level zoomLevelX = (double)screen2.deviceXDPI / (double)screen2.logicalXDPI; zoomLevelY = (double)screen2.deviceYDPI / (double)screen2.logicalYDPI; // Calculate the viewport rectangle, needed if there is a frame around the html window LOG.DebugFormat("Screen {0}x{1}", ScaleX(screen.width), ScaleY(screen.height)); //LOG.DebugFormat("Screen location {0},{1}", window3.screenLeft, window3.screenTop); LOG.DebugFormat("Window rectangle {0}", clientRectangle); LOG.DebugFormat("Client size {0}x{1}", ClientWidth, ClientHeight); int diffX = clientRectangle.Width - ClientWidth; int diffY = clientRectangle.Height - ClientHeight; // If there is a border around the inner window, the diff == 4 // If there is a border AND a scrollbar the diff == 20 if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) { Point viewportOffset = new Point(2, 2); Size viewportSize = new Size(ClientWidth, ClientHeight); viewportRectangle = new Rectangle(viewportOffset, viewportSize); LOG.DebugFormat("viewportRect {0}", viewportRectangle); } } LOG.DebugFormat("Zoomlevel {0}, {1}", zoomLevelX, zoomLevelY); } catch (Exception e) { LOG.Warn("Can't get certain properties for documents, using default. Due to: ", e); } try { LOG.DebugFormat("Calculated location {0} for {1}", startLocation, document2.title); if (name == null) { name = document2.title; } } catch (Exception e) { LOG.Warn("Problem while trying to get document title!", e); } try { url = document2.url; } catch (Exception e) { LOG.Warn("Problem while trying to get document url!", e); } sourceLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); destinationLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y)); if (parent != null) { return; } try { IHTMLFramesCollection2 frameCollection = (IHTMLFramesCollection2)document2.frames; for (int frame = 0; frame < frameCollection.length; frame++) { try { IHTMLWindow2 frameWindow = frameCollection.item(frame); DocumentContainer frameData = new DocumentContainer(frameWindow, contentWindow, this); // check if frame is hidden if (!frameData.isHidden) { LOG.DebugFormat("Creating DocumentContainer for Frame {0} found in window with rectangle {1}", frameData.name, frameData.SourceRectangle); frames.Add(frameData); } else { LOG.DebugFormat("Skipping frame {0}", frameData.Name); } } catch (Exception e) { LOG.Warn("Problem while trying to get information from a frame, skipping the frame!", e); } } } catch (Exception ex) { LOG.Warn("Problem while trying to get the frames, skipping!", ex); } try { // Correct iframe locations foreach (IHTMLElement frameElement in document3.getElementsByTagName("IFRAME")) { try { CorrectFrameLocations(frameElement); } catch (Exception e) { LOG.Warn("Problem while trying to get information from an iframe, skipping the frame!", e); } } } catch (Exception ex) { LOG.Warn("Problem while trying to get the iframes, skipping!", ex); } }
/// <summary> /// Public constructor. /// </summary> /// <param name="html">Html string to be processed.</param> public HtmlProcessor(string html) { if (string.IsNullOrEmpty(html)) { throw new ArgumentException("HTML string can not be null or empty.", "html"); } this.documentSource = html; this.doc2 = new HTMLDocumentClass(); this.doc2.write(new object[] { html }); //while (this.doc2.readyState != "complete" && this.doc2.readyState != "interactive") //{ // System.Windows.Forms.Application.DoEvents(); //} this.doc3 = (IHTMLDocument3)this.doc2; this.doc4 = (IHTMLDocument4)this.doc2; this.doc5 = (IHTMLDocument5)this.doc2; this.InnerText = (this.doc2.body == null) ? null : this.doc2.body.innerText; this.Title = this.doc2.title; this._elements = new List <DomElement>(); IHTMLElementCollection collection = this.doc2.all; foreach (var item in collection) { var element = (IHTMLElement)item; if (element != null) { DomElement domElement = new DomElement { Class = element.className, InnerHtml = element.innerHTML.TrimSafe(), OuterHtml = element.outerHTML.TrimSafe(), InnerText = element.innerText.TrimSafe(), Id = element.id, TagName = element.tagName.ToLowerInvariant() }; domElement.Attributes = new NameValueCollection(); if (element.outerHTML.IsNullOrEmpty()) { continue; } //@"<INPUT onblur=google&&google.fade&&google.fade() class=lst title='Google Search' value=TESTING maxLength=2048 size=55 name=q autocomplete='off' init='true'/>"; string node = element.outerHTML.Substring(0, element.outerHTML.IndexOf(">") + 1); string pattern = @" (?:<)(?<Tag>[^\s/>]+) # Extract the tag name. (?![/>]) # Stop if /> is found # -- Extract Attributes Key Value Pairs -- ((?:\s+) # One to many spaces start the attribute (?<Key>[^=]+) # Name/key of the attribute (?:=) # Equals sign needs to be matched, but not captured. (?([\x22\x27]) # If quotes are found (?:[\x22\x27]) (?<Value>[^\x22\x27]+) # Place the value into named Capture (?:[\x22\x27]) | # Else no quotes (?<Value>[^\s/>]*) # Place the value into named Capture ) )+ # -- One to many attributes found!"; //http://omegacoder.com/?p=512 var attr = (from Match mt in Regex.Matches(node, pattern, RegexOptions.IgnorePatternWhitespace) select new { Name = mt.Groups["Tag"], Attrs = (from cpKey in mt.Groups["Key"].Captures.Cast <Capture>().Select((a, i) => new { a.Value, i }) join cpValue in mt.Groups["Value"].Captures.Cast <Capture>().Select((b, i) => new { b.Value, i }) on cpKey.i equals cpValue.i select new KeyValuePair <string, string>(cpKey.Value, cpValue.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value) }).FirstOrDefault(); if (attr != null) { var attributes = attr.Attrs; foreach (KeyValuePair <string, string> kvp in attributes) { if (!string.IsNullOrEmpty(kvp.Value)) { domElement.Attributes.Add(kvp.Key.ToLowerInvariant(), kvp.Value); } } } this._elements.Add(domElement); } } }