UnauthorizedAccessException当HTML内容code。使用web浏览器的IFrame [英] UnauthorizedAccessException when get Html code IFrame using WebBrowser

查看:187
本文介绍了UnauthorizedAccessException当HTML内容code。使用web浏览器的IFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE或Chrome使用开发工具,我得到的html code一帧。没问题。

Using Developer Tools in IE or Chrome, I get html code for a frame. No problem.

现在,我想用C#应用程序做到这一点。我有System.Windows.Form.WebBrowser在VS2010。我尝试获取HTML code一帧。

Now, I want do it using C# application. I have System.Windows.Form.WebBrowser in VS2010. I try get Html code for a Frame.

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

但我得到的错误UnauthorizedAccessException。

but I get error UnauthorizedAccessException.

我再试一次像这样的Read使用的网页浏览器C# iframe的HTML code,但我得到了同样的错误。

I try again like this Read HTML code from iframe using Webbrowser C# but I get the same error.

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

有什么建议?

推荐答案

您没写,但我假设的iFrame包括来自不同的域内容。现代浏览器包括一些防XSS机制,这样,给黑客更多的工作。

You didn't write it, but i assume that the iFrame includes content from different domain. Modern browsers includes some anti-XSS mechanism, like this, to give attacker more work.

在这种情况下,最简单的方法是检查什么显示的iFrame里面,然后手动下载里面使用Web客户端的网页。如果它是某种会员区,您可能需要复制的cookie。所以,刚刚获得iframe的src属性,并使用 WebClient.DownloadString 下载此页面。

In that case, the most easy way is to check what's showing inside the iFrame, and then manually download the web page that inside using WebClient. if it's some kind of members area, you might have to copy the cookies. so, just get the src attribute of the iframe and use WebClient.DownloadString to download this page.

这篇关于UnauthorizedAccessException当HTML内容code。使用web浏览器的IFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆