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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>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.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

How about something in jscript...

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;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.