How do I access "View Source" through VBS?

Posted on 2008-11-04
Last Modified: 2013-12-08
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.
Question by:jgoeders
    LVL 14

    Accepted Solution

    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

    LVL 82

    Expert Comment

    >>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.
    LVL 2

    Author Comment

    almost. but the XMLHTTP sends another request for the web page.  I need the source of the original request sent by IE.
    LVL 14

    Expert Comment

    How about something in jscript...
    LVL 4

    Assisted Solution


    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.
    LVL 14

    Expert Comment

    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;

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
    This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
    How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now