Script Tips

IE Does What You Script

Reader asks for script to open IE and dump page contents into a text file. Don obliges.

I’ve written before about automating Internet Explorer, and this week’s script answers a question sent in by a reader. He wanted to write a script that would make IE navigate to a Web page, and then save the Web page’s contents as a text file. This’ll do just that:

Dim objIE, objFSO, objTS
Set objIE = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objIE, objFSO, objTS
Set objIE = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")

objIE.Navigate("http://www.scriptinganswers.com")
Do While objIE.Busy
   WScript.Sleep 500
Loop

Set objTS = objFSO.CreateTextFile("C:\WebPage.html")
objTS.Write objIE.Document.Body.InnerHTML
objTS.Close

You’ll notice that, because I never set objIE.Visible = True, IE never actually appears -- it just does its thing and then goes away. This technique has a number of handy uses, and because objIE.Document.Body.InnerHTML is just a string, you can use string handling functions in VBScript to check for specific words or phrases, or perform other tests.

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is an Author/Evangelist for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.