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

IE.document.body.InnerHTML

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

Open in new window

0
 
hieloCommented:
>>Right now I have
>>IE.document.body.InnerHTML
>>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.
0
 
jgoedersAuthor Commented:
almost. but the XMLHTTP sends another request for the web page.  I need the source of the original request sent by IE.
0
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.

 
rejoinderCommented:
How about something in jscript...
http://www.web-source.net/javascript_view_source2.htm
0
 
ChizlConnect With a Mentor Commented:
rejoinder:

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.
0
 
rejoinderCommented:
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;
http://technet.microsoft.com/en-us/magazine/cc987541.aspx
0
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.