c# - 如何从 iframe 访问 HTML
问题描述
我有一个像
<iframe tabindex="2" class="s-basicpanel s-panel-border" id="test1">
<html>
<body id ="test"></body>
</html>
</iframe>
我必须在正文标签中添加内部文本。
我做了以下事情:
public void testData()
{
mshtml.IHTMLWindow2 frame2 = IEDOMDocument.frames.item(ref 0);
if (frame2 != null)
{
if(frame2.document.body != null)
{
mshtml.IHTMLElementCollection allElements = (mshtml.IHTMLElementCollection)frame2.document.body.all;
foreach(mshtml.IHTMLElement test in allElements)
{
Log("Tag Name:"+test.tagName);
if(test.tagName.ToLower() == "iframe")
{
string iframeId=test.getAttribute("id").ToString();
if(iframeId.Equals("test1"))
{
Log("found elemnet***");
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)test.children; // return me empty collection
}
}
}
}
}
}
当我尝试访问 iframe 中的内部集合时使用上面的代码,它为我提供了空集合。
经过大量调试后,我知道问题出在 iframe 中的数据上。 我需要有人来帮忙。
解决方案
推荐阅读
- c - 无法摆脱应该检查输入的值是否正确的循环
- svg - 如何将 SVG 块的右侧稍微向后转换?
- ruby-on-rails - Rails 5:运行时弹簧出错设计:安装
- php - Laravel 提取值并附加附加字符串
- r - 如何安装gpclib?
- swift - class in playground vs in program file
- c - 内存地址在 C 中是否可移植?
- javascript - 如何在nestjs应用程序中使用时刻
- python - Mac 上是否有 Python 可访问的 API 用于访问和操作 Mail.app 中的电子邮件?
- bash - Docker 运行 bash --init-file