Access elements inside html <embed> tag source html using VB.Net

I use the SHDocVw.InternetExplorer API in the VB.Net WinForms application to retrieve items from Internet Explorer. I can easily access the elements inside the parent document and the frame elements, but I can not access the elements inside the paste container. Here is an example code:

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? 

And here is the html sample:

Sample.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> 

test.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> 

How can I access the button and label inside Test.html loaded in Sample.html using the 'embed' tag?

Change 1 :

According to my research, I can access the document inside the "object" container using the .contentDocument property of the "object" element, but the same does not work for the "embed" container.

I can get some comObject using the getSVGDocument () property in the "embed" container, but cannot pass it to mshtml.IHTMLDocument2

+6
source share
1 answer

Well, I used the “Html Agility Pack” to parse the html here, and it's pretty amazing, you can get all the inline elements on your page and they will read / analyze the internal content. http://html-agility-pack.net/

My example:

 '<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 
0
source

Source: https://habr.com/ru/post/1014321/


All Articles