【问题标题】:How to retrieve HTML from Webbrowser control out of frames in .net (c#)如何从.net(c#)中的框架中从Webbrowser控件中检索HTML
【发布时间】:2010-12-02 16:37:55
【问题描述】:

我知道我可以通过以下方式获取 Webbrowser 控件的 HTML(源代码):

HtmlDocument htmldoc = webBrowser1.Document

但这确实只提供了“父页面”的html代码。如果网页使用框架,它不会返回包括框架在内的整个页面的 html 代码。

如何获取包含框架的完整 HTML 代码 - 或选择单个框架并获取该框架的 html 代码?

【问题讨论】:

    标签: c# html webbrowser-control frames


    【解决方案1】:

    我最好的选择是:

    WB1.Document.Window.Frames[0].Document.GetElementsByTagName("HTML")[0].OuterHtml
    

    【讨论】:

      【解决方案2】:
       HtmlWindow frame = webBrowser1.Document.Window.Frames[0];
      
       string str = frame.Document.Body.OuterHtml;
      

      【讨论】:

      • 如果 iframe 有不同的 url 你会得到 UnauthorizedAccessException。
      猜你喜欢
      • 2011-11-29
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2013-09-30
      • 2020-03-19
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多