【问题标题】:UnauthorizedAccessException when get Html code IFrame using WebBrowser使用 WebBrowser 获取 Html 代码 IFrame 时出现 UnauthorizedAccessException
【发布时间】:2012-09-30 08:02:05
【问题描述】:

在 IE 或 Chrome 中使用开发人员工具,我得到一个框架的 html 代码。没问题。

现在,我想使用 C# 应用程序来实现。我在 VS2010 中有 System.Windows.Form.WebBrowser。我尝试获取 Frame 的 Html 代码。

 public static HtmlElementCollection GetElementsByTagNameForFrame(this WebBrowser wb, 
                                             string tag, string idFrame)
 {
      return wb.Document.Window.Frames[idFrame].Document.GetElementsByTagName(tag);
 }

但我收到错误 UnauthorizedAccessException。

我像这样Read HTML code from iframe using Webbrowser C# 再次尝试,但我得到了同样的错误。

string content = doc.Window.Frames["injected-iframe"].WindowFrameElement.InnerText; 

有什么建议吗?

【问题讨论】:

    标签: c# iframe browser unauthorizedaccessexcepti


    【解决方案1】:

    不是你写的,但我认为 iFrame 包含来自不同域的内容。现代浏览器包含一些反 XSS 机制,比如这样,给攻击者更多的工作。

    在这种情况下,最简单的方法是检查 iFrame 中显示的内容,然后使用 WebClient 手动下载其中的网页。如果是某种会员区,您可能需要复制 cookie。所以,只需获取 iframe 的 src 属性并使用WebClient.DownloadString 下载此页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      相关资源
      最近更新 更多