2

I want to get the HTML code of a webpage after it has been modified (similar to one that we see in inspect element tab of a browser) and I want to do it programatically (if possible using python or any other programming language). Can someone suggest how I might be able to proceed with this? I know its possible since browsers are able to do it.

6
  • javascript: .innerHTML, jQuery: .html() Commented Jun 1, 2016 at 11:55
  • In javascript you could do something like: 'getElementyByTagName('HTML'), right before the block code ends of the event fired, which made the DOM manipulation :); as Ashish Kumar mentioned above, .innerHTML gives you the HTML inside the element, if you need only text, you could do .text / .value on the element in question Commented Jun 1, 2016 at 11:56
  • What is your usecase? The current answers asume a browser. If you are scraping you should use something like selenium. Commented Jun 1, 2016 at 12:09
  • I am hitting an API which gives me a HTML(with javascript). I want to parse the html(after javascript modification) and return some specific tag-fields. Commented Jun 1, 2016 at 12:17
  • With what are you doing the requests to the api? Commented Jun 1, 2016 at 12:20

2 Answers 2

1

As the server has no access to client window after client-side changes, you have to use client side languages.

In jquery:

var fullCode= "<html>" + $("html").html() + "</html>";

if you want also to include the Doctype:

var node = document.doctype;
var fullCode = "<!DOCTYPE "
         + node.name
         + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
         + (!node.publicId && node.systemId ? ' SYSTEM' : '') 
         + (node.systemId ? ' "' + node.systemId + '"' : '')
         + '>';
fullcode += "<html>" + $("html").html() + "</html>";

Thanks to this

Sign up to request clarification or add additional context in comments.

Comments

0

Using JQuery you can achieve this by the following code

$(document).ready(function(){
    var html = "<html>"+$('html').html()+"</html>";
});

1 Comment

This doesn't really make it so that the page content is refreshed when a function is fired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.