利用webBrowser獲取頁面iframe中的內容


1.獲取frame的document

  HtmlDocument htmlDoc = webBrowser1.Document;
  htmlDoc = webBrowser1.Document.Window.Frames["frmRpt"].Document;

  "frmRpt"為iframe的name;

2.獲取frame的源文件

MessageBox.Show(webBrowser1.Document.Window.Frames["main"].Document.Body.InnerHtml);

3.獲取frame的HTMLDocument接口

HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
object j;
for (int i = 0; i < doc.parentWindow.frames.length; i++)
{
       j = i;
       HTMLWindow2Class frame = doc.parentWindow.frames.item(ref j) as HTMLWindow2Class;
       if (frame.name == "main")
        {                  
              MessageBox.Show(frame.document.title);                   
        }
}     

4.獲取frame的IHTMLDocument2接口

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.Window.Frames["main"].Document.DomDocument;

5.取得frame中被點擊的連接

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
      string url = webBrowser1.Document.Window.Frames["main"].Document.ActiveElement.GetAttribute("src");
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM