开发者

Read HTML code from iframe using Webbrowser C#

开发者 https://www.devze.com 2023-01-24 15:26 出处:网络
How to read IFRAME html code using WebBrowser? I have site with iframe, and after few clicks new URL opens inside this IFRAME with some portion of HTML CODE. Is there a possiblity to read this?. When

How to read IFRAME html code using WebBrowser?

I have site with iframe, and after few clicks new URL opens inside this IFRAME with some portion of HTML CODE. Is there a possiblity to read this?. When I am trying to Navigate() to this URL, I am redirected to main page of this site (it is not possible to open this link twice).

Uri IFRAME_URL = webBrowser1.Document.Window.Frames[0].Url;

Maybe there is something similar to:

开发者_如何学CUri IFRAME_URL = webBrowser1.Document.Window.Frames[0].  ... DOCUMENTTEXT;


Try:

string content = webBrowser1.Document.Window.Frames[0].WindowFrameElement.InnerText;


You can also acquire various items via mshtml types:

Set a reference to the "Microsoft HTML Object Library" under COM references.

Set your using statement:

using mshtml;

Then tap into the mshtml API to snatch the source:

HTMLFrameBase frame = yourWebBrowserControl.Document.GetElementById( "yourFrameId" ).DomElement as HTMLFrameBase;

If "frame" isn't null after that line, it has a lot of items hanging off it for your use.


try:

string content = webBrowser1.Document.Window.Frames[0].Document.Body.InnerText


A WebBrowser Control window can contain more that one iframe and .net supports frame collection so why not use something like this:

// Setup a string variable...
string html = string.Empty;

// webBrowser1.Document.Window.Frames gets a collection of iframes contained in the current document...
// HTMLWindow is the iterator for the Collection...
foreach (HtmlWindow frame in webBrowser1.Document.Window.Frames)
{
html += frame.Document.Body.OuterHtml;
}

This way, maybe with a little adjustment you can get all you need from the iframe containers you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消