【发布时间】:2013-01-03 22:33:45
【问题描述】:
好吧,我的程序正在读取一个 Web 目标,该目标在正文的某处有我想要读取的 iframe。
我的 html 源代码
<html>
...
<iframe src="http://www.mysite.com" ></iframe>
...
</html>
在我的程序中,我有一个方法将源作为字符串返回
public static string get_url_source(string url)
{
using (WebClient client = new WebClient())
{
return client.DownloadString(url);
}
}
我的问题是我想在读取源代码时获取 iframe 的源代码,就像在正常浏览中一样。
我只能通过使用WebBrowser Class 来做到这一点,还是有办法在 WebClient 甚至其他类中做到这一点?
真正的问题: 给定一个 url,我如何获取外部 html?欢迎任何方法。
【问题讨论】:
-
猜你可以通过java脚本访问url ..
-
请注意,如果您从另一个域访问页面,您可能会遇到跨站点脚本的安全问题。
-
是的 iframe 来自另一个域,但为什么会出现问题?
-
@Incognito:在 wiki 上查看 [Cross-site scripting]
-
实际上我的页面涉及脚本,经过一番研究,我发现迄今为止最接近的解决方案是这样 > webBrowser1.Document.ActiveElement.OuterHtml.ToString();所以我需要页面的外部html。另一个类似的问题在这里 -> stackoverflow.com/questions/10562051/…
标签: c# browser html-parsing webclient