访问html中的元素<;嵌入>;使用VB.Net标记源html

访问html中的元素<;嵌入>;使用VB.Net标记源html,vb.net,internet-explorer,mshtml,shdocvw,Vb.net,Internet Explorer,Mshtml,Shdocvw,我在Vb.NETWinForms应用程序中使用SHDocVw.InternetExplorer API从Internet Explorer获取元素。我可以轻松访问父文档和框架元素中的元素,但无法访问“嵌入”容器中的元素。以下是示例代码: Dim ie As SHDocVw.InternetExplorer ie.Navigate("Some URL") ie.Visible = True Dim ieDoc As mshtml.IHTMLDocument2 = i

我在Vb.NETWinForms应用程序中使用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:

Sample.html


样品
嗯,我一直在这里使用“Html敏捷包”解析Html,非常棒, 您可以在页面中获取所有嵌入元素,并读取/解析内部内容。

我的样本:

'<html xmlns='http://www.w3.org/1999/xhtml'>
'<head>
'    <title>Sample</title> 
'</head>
'<body>
'    <embed src='http://stackoverflow.com/questions/41806246/access-elements-inside-html-embed-tag-source-html-using-vb-net' name='test1'/>
'</body>
'</html>
'The htmlCode string:

Dim htmlCode As String = "<html xmlns='http://www.w3.org/1999/xhtml'><head><title>Sample</title></head><body><embed src='http://stackoverflow.com/questions/41806246/access-elements-inside-html-embed-tag-source-html-using-vb-net' name='test1'/></body></html>";

Dim client As New WebClient()

Dim doc = New HtmlDocument()
doc.LoadHtml(htmlCode)

Dim nodes = doc.DocumentNode.Descendants("embed")

For Each item As var In nodes
    Dim srcEmded = item.GetAttributeValue("src", "")

    If Not String.IsNullOrWhiteSpace(srcEmded) Then

        Dim yourEmbedHtml As String = client.DownloadString(srcEmded)
        'Do what you want with yourEmbedHtml

    End If
Next
'
'
“样本
'
'
'    
'
'
'htmlCode字符串:
Dim htmlCode为String=“Sample”;
作为新WebClient()的Dim客户端
Dim doc=新的HtmlDocument()
doc.LoadHtml(htmlCode)
Dim节点=doc.DocumentNode.substands(“嵌入”)
将每个项目作为节点中的变量
Dim srcemd=item.GetAttributeValue(“src”,“”)
如果不是String.IsNullOrWhiteSpace(srcEmded),则
将HTML设置为String=client.DownloadString(srcEmded)
“用你的HTML做你想做的事
如果结束
下一个

您有完整的复制项目吗?嵌入并不总是根据安全设置、IE版本或任何上下文工作。是的,我有复制项目。此外,本文中共享的代码足以重现该问题。嵌入在我的IE版本11中运行良好。我面临的问题是如何获取嵌入到嵌入容器中的HTMLDocument。我正在用我的新发现更新这个问题。我要求一个复制项目,因为你的代码不足以复制。如果您需要帮助,请发布完整的示例。有没有办法在SO上共享使用Visual Studio创建的完整示例项目?这里是完整示例项目的链接不能使用agility pack作为我的动机不仅仅是解析内容,我正在浏览器元素上实现各种事件以捕获实时用户操作。