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.
Asked
Active
Viewed 933 times
2
-
javascript: `.innerHTML`, jQuery: `.html()` – Ashish Kumar Jun 01 '16 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 – iyerrama29 Jun 01 '16 at 11:56
-
What is your usecase? The current answers asume a browser. If you are scraping you should use something like selenium. – syntonym Jun 01 '16 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. – shubham003 Jun 01 '16 at 12:17
-
With what are you doing the requests to the api? – syntonym Jun 01 '16 at 12:20
-
The request are simple POST api calls through urllib.request module of python3. – shubham003 Jun 01 '16 at 12:24
2 Answers
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

Community
- 1
- 1

Ali Sheikhpour
- 10,475
- 5
- 41
- 82
0
Using JQuery you can achieve this by the following code
$(document).ready(function(){
var html = "<html>"+$('html').html()+"</html>";
});
-
This doesn't really make it so that the page content is refreshed when a function is fired. – thepio Jun 01 '16 at 12:18