How to (programmatically) get fully computed HTML (instead of the original HTML)?

I am trying to learn jQuery and trying to create a Chrome extension. Hacked around, I tried to parse a web page that loads javascript and Ajax requests to generate my HTML code, how can I programmatically get the final computed HTML that is parsed by the browser instead of the original HTML?

My question is inspired by this other question: how to get fully computed HTML (instead of the original HTML)?

The difference is that I really want to understand if this is possible and how to do it programmatically, ideally with JavaScript.

I have already tried using: $(document).ajaxComplete()

But without a positive result.

Updated based on comments:

I do not have access to the code, I can only send a request for receipt to the website. Then the website will return me the source of the page, which itself contains ajax or javascript. I want Ajax and JavaScript to be rendered so that I can parse everything no matter what it appears.

+4
source share
1 answer

To get the markup of your document after scripting , you have to add that markup to the iframe or the like. Then you can get the root of the node through yourFrame.contentDocument.documentElement*.

AJAX Blob, , iframe src 'data:text/html,' + encodeURIComponent(textResponse).

var iframe = document.createElement('iframe');
// since we need to append the iframe for it to load, lets hide it
iframe.width = iframe.height = 0;
iframe.setAttribute('style', 'position:absolute; opacity:0;')

$('body').append(iframe); // this is a jQuery question...

iframe.src = URL.createObjectURL(AJAXresponseAsBlob);
// here we will trigger the catching at page load
iframe.onload = function() {
  var outer = iframe.contentDocument.documentElement.outerHTML;
  iframe.parentNode.removeChild(iframe); // we don't need it anymore
  doSomethingWith(outer);
}

( )

* IIRC, , iframe, , .

0

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


All Articles