我不确定WebBrowser.DocumentText
是否仅包含顶级文档来源或框架文档文本。无法从MSDN页面找到。
答案 0 :(得分:0)
不,不。我接下来试过了:
DocumentText:
File.WriteAllText(@"C:\doc.txt", webBrowser1.DocumentText, Encoding.UTF8);
的getElementsByTagName( “HTML”)
HtmlElement elem;
if (webBrowser1.Document != null)
{
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("HTML");
if (elems.Count == 1)
{
elem = elems[0];
string pageSource = elem.OuterHtml;
File.WriteAllText(@"C:\doc.txt", pageSource, Encoding.UTF8);
}
}
IOleCommandTarget
public void ShowSource()
{
IOleCommandTarget cmdt = null;
object o = null;
object oIE = null;
try {
cmdt = (IOleCommandTarget)this.Document.DomDocument;
cmdt.Exec(cmdGUID, oCommands.ViewSource, 1, o, o);
} catch (Exception ex) {
throw new Exception(ex.Message.ToString(), ex.InnerException);
} finally {
cmdt = null;
}
}
唯一的方法是浏览所有框架文档。
已更新如果iframe有不同的网址,您将获得UnauthorizedAccessException when trying to retrieve iframe document