In my case, I needed to demand to parse the page header AND and have all the other kindness of jQuery, except for the startup scripts. Here is my solution that seems to work.
$.get('/somepage.htm', function (data) { // excluded code to extract title for simplicity var bodySI = data.indexOf('<body>') + '<body>'.length, bodyEI = data.indexOf('</body>'), body = data.substr(bodySI, bodyEI - bodySI), $body; body = body.replace(/<script[^>]*>/gi, ' <!-- '); body = body.replace(/<\/script>/gi, ' --> '); //console.log(body); $body = $('<div>').html(body); console.log($body.html()); });
This kind of shortcuts worries about the script because you are not trying to remove the tags and contents of the script, instead you replace them with comment rendering schemes so that they are useless to break, since you will have comments restricting your script declarations.
Let me know if this is still a problem, as it will help me too.
Jason Sebring Oct 03 2018-12-12T00: 00Z
source share