Grav
Grav

Reputation: 1714

Get DOM of a dynamically rendered webpage

Is it possible to programmatically get the resulting DOM of a dynamically rendered webpage? I.e. scripting the browser to load a URL, render the page (using javascript etc) and outputting the resulting DOM.

Upvotes: 3

Views: 810

Answers (1)

Erx_VB.NExT.Coder
Erx_VB.NExT.Coder

Reputation: 4856

Yes, if you get a reference to MSHTML.IHTMLDocument2 say, declare hDoc as this, you will get intellisense to help you loop through the items and elements in that document. Remember, the reference is LIVE, meaning, any changes that are made to the document object (page) via any means, JavaScript, or changes you make with your page reference, will be updated and displayed on the page, and you will be able to query and retrieve the new values by get accessing the elements you need. Ff course, when you visit a link from there on, the next page's DOM will be the LIVE DOM.

If you have any specific questions, let me know and I will help you out. I'm hoping I understood your question correctly also.

Example:

Dim hDoc As IHTMLDocument2

Set hDoc = WebBrowser1.Document

For i = 0 to hDoc.All.length - 1
  MsgBox hDoc.All(i).tagName & ": OuterHTML: " & hDoc.All(i).outerHTML
Next i

This will show you the tagNameand actual HTML for each element on the page (LIVE).

Upvotes: 1

Related Questions