How to Download a Web Page With VBScript
VBScript uses the HttpWebRequest control to download websites and interface with the website's pages. Download the page and store it as a file, or display the downloaded code to a Web page. The HttpWebRequest control opens the Web page in the server's memory, and the information downloaded is the raw HTML displayed as if the code was displayed in a regular browser.
Instructions
-
-
1
Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET," then click the "Visual Studio" shortcut. Open your VBScript project to open the Web forms.
-
2
Create the HttpWebRequest variable. You must instantiate a class to use it in your VBScript. The following code instantiates the class:
Dim web As HttpWebRequest
-
-
3
Retrieve the website's code and set the response to a variable. You request the server's information, but you must then save the server response to a "response" variable. The following code shows you how to retrieve the data and store the response in a "response" variable:
web WebRequest.Create("http://mydomain.com/page.aspx")
Dim response As HttpWebResponse = CType(web.GetResponse(), HttpWebResponse)
The code above retrieves the HTML code from "mydomain.com/page.aspx." Replace this URL with your own address. The response is saved to the variable labeled "response."
-
4
Store the response or print it to the screen. The following code stores the response to a stream, which is used to print the output to the reader's screen:
Dim read As New StreamReader(response)
Dim html As String = read.ReadToEnd()
Console.WriteLine(html)
-
1