如何从Web浏览器控件中检索HTML .net(c#)中的帧

2 html c# frames webbrowser-control

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

HtmlDocument htmldoc = webBrowser1.Document

但这只提供了"父页面"的html代码.如果网页使用框架,它不会返回整个页面的html代码,包括框架.

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

小智 5

 HtmlWindow frame = webBrowser1.Document.Window.Frames[0];

 string str = frame.Document.Body.OuterHtml;
Run Code Online (Sandbox Code Playgroud)

  • 如果iframe有不同的url,您将获得UnauthorizedAccessException. (2认同)