我在我的 Vb.Net WinForms 应用程序中使用 SHDocVw.InternetExplorer API 从 Internet Explorer 获取元素。我可以轻松访问父文档和框架元素中的元素,但无法访问“嵌入”容器中的元素。这是示例代码:
Dim ie As SHDocVw.InternetExplorer
ie.Navigate("Some URL")
ie.Visible = True
Dim ieDoc As mshtml.IHTMLDocument2 = ie.Document
'All Elements
Dim allElements = ieDoc.all
'Frames
Dim allFrames = ieDoc.frames
'Fetch each frame and use its document to get all elements
Dim allEmbed = ieDoc.embeds
'How to fetch document inside embed to access its elements?
这是一个示例html:
示例.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
</head>
<body>
<embed src="test.html" name="test1"/>
</body>
</html>
测试.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample</title>
</head>
<body bgcolor="#FFFFFF">
<button>Button1</button>
<label>Test 1</label>
</body>
</html>
如何使用“嵌入”标签访问 Sample.html 中加载的 Test.html 内的按钮和标签?
编辑 1:
根据我的研究,我可以使用“object”元素的 .contentDocument 属性访问“object”容器内的文档,但同样不适用于“embed”容器。
我可以使用“嵌入”容器上的 getSVGDocument() 属性获取一些 comObject,但无法将其转换为 mshtml.IHTMLDocument2