How do I access "View Source" through VBS?

In IE you can go View -> Source.

How can I do this through code? Preferrably through a VBS script?

Right now I have


this isn't giving me the same results as going View Source on a web page.
Who is Participating?
rejoinderConnect With a Mentor Commented:
Have you tried something like this...
wscript.echo GetHtml("")
Function GetHtml(sURL) 
    Set oHTML = CreateObject("Microsoft.XMLHTTP")
    Set oWeb = CreateObject("InternetExplorer.Application")
    oWeb.navigate (sURL) "GET" , sURL, false
    GetHtml = oHTML.responseText
End function

Open in new window

>>Right now I have
>>this isn't giving me the same results as going View Source on a web page.
That's because the browser "cleans" the source code that the server sends and uses the "clean" version to render the page. So programmatically, when accessing the innerHTML property of any element, the browser will give you the clean version only.

If you want the actual "non-clean" version, you will need to request the document again via ajax.
jgoedersAuthor Commented:
almost. but the XMLHTTP sends another request for the web page.  I need the source of the original request sent by IE.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

How about something in jscript...
ChizlConnect With a Mentor Commented:

In your code, you don't need:
    Set oWeb = CreateObject("InternetExplorer.Application")
    oWeb.navigate (sURL)

However, the rest of it will give you exactly what you see on view source.    Problem is, not everyone has the XMLHTTP object installed.   It's not part of the default with Windows.  You must install MSXML to get it.
I don't know if this will help view the code on your page but I spotted this tool today and thought you might want to have a look;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.