Get DOM of dynamically displayed web page

Is it possible to programmatically retrieve the resulting DOM of a dynamically displayed web page? That is, browser scripting to load the URL, render the page (using javascript, etc.) and output the final DOM.

+3
source share
1 answer

Yes, if you get a link to MSHTML.IHTMLDocument2, say declare hDoc like this, you will get intellisense to help you iterate over the elements and elements in this document. Remember that the LIVE link, that is, any changes made to the object (page) documentby any means, JavaScript or changes you made using the page link, will be updated and displayed on the page, and you will be able to request and receive new ones values ​​by accessing the items you need. Of course, when you visit the link from there, the next DOM page will be LIVE DOM.

If you have any specific questions, let me know and I will help you. I hope I understand your question correctly.

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 also show you the tagNameactual HTML for each element on the page (LIVE).

+1

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


All Articles