views:

218

answers:

3

How do i get the full! HTML source of a web page, after it has run some JavaScript code which has made manipulations to the HTML source.

I'm using the WebbrowserControl of VB.Net, i'd like to create an extra function of my custom webbrowsercontrol which receives the full HTML source.

Thanks in advance

A: 

The best way is to use Chrome or Firefox which let you browse the DOM, CSS and HTML in real time (and change it if you want).

edit

The logic of @JohnFx's comment is fundamentally flawed (and maybe the OP's question). There is no guarantee that javascript (or other manipulators) will change the HTML of a page, most often (esp if they are programmed well) they will only change the DOM. If the goal is to debug or learn then you need to use firebug via firefox or chrome.

Of course it might be the case he wants to debug some javascript that changes the html and not the DOM, then @JohnFx's answer might work (I've never done such a thing.)

Hogan
That doesn't really answer the question. nicoJuicy is looking for a way to get the modified HTML via the webbrowsercontrol interface in code.
JohnFx
@JohnFx: See edit above.
Hogan
Again, he isn't trying to debug or learn anything. He wants to get the final HTML of the page in code, which may have been manipulated by client side scripts. I have no idea what he is doing with it, but it is clear that he isn't just looking for a way to see the final HTML content.
JohnFx
:) So we know he isn't trying to debug or learn anything, what exactly is he trying to do... this might help...
Hogan
I'm trying to automise website actions into an application :)The website uses AJAX (= JS) and so i wan't to see the full html source with the values it grabbed from the db.
NicoJuicy
Ah, so you are trying to debug.
Hogan
If you are using jQuery or another framework to change the page via AJAX then looking at the HTML like @JohnFx suggests won't work. They change the DOM and don't change the HTML.
Hogan
A: 

Elaborating on @Hogan's answer a bit. I'm not sure of a way to do this in a vanilla install of Firefox (correct me if I'm wrong), but an extension such a Firebug will allow you to do this quite nicely.

jbruce2112
Yes, you need Firebug. Or in Safari use the Develop->Show Web Inspector
philfreo
Again, the question is about doing this in code. No interactively.
JohnFx
You are right, Firefox requires Firebug, Chrome is just a right click on an element, some hot key I don't know, or the developer menu item.
Hogan
A: 

The trick is going to be finding a way to notify the control about whether the JS is done running. You might be able to do that by having the JS set a form element' value (isJSComplete) when it has completed and polling with the web browser control.

Use the following code to check a form value to see if it is ready

MyBrowserControl.document.getElementById('isJSComplete');

Use the following code to pull the HTML from the page.

MyBrowserControl.Document.documentElement.OuterHTML

Better yet, here is an article showing how to wire up JS events to be handled by the WebBrowser control. You could just fire an event when the JS is done and have your code trap that event and then pull the HTML using the above approach.

JohnFx
This is what i'm looking for.I'm going to test it out this evening, thanks in advance!
NicoJuicy