Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to create a script to download the HTML source to a text for html file locally?

For example, if I wanted to archive the HTML of Google.com each day.

I'm up for batch, VBS or PS1 but preferably BAT or VBS.

I may be using this on many computers so preferably, I'd like a built in script solution only.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

With PowerShell:

# $url is the URL you want to download
$url = "http://www.google.com/"

# $path is the location where you want to save the file
$path = "C:\Users\Public\Downloads\google.html"

$client = New-Object System.Net.WebClient
$client.DownloadFile($url, $path)

With VBScript:

' 'url' is the url you want to download
url = "http://www.google.com/"

' 'path' is the location where you want to save the file
path = "C:\Users\Public\Downloads\google.html"

Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", url, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
  Set objADOStream = CreateObject("ADODB.Stream")
  objADOStream.Open
  objADOStream.Type = 1 'adTypeBinary
  objADOStream.Write objXMLHTTP.ResponseBody
  objADOStream.Position = 0    'Set the stream position to the start
  Set objFSO = Createobject("Scripting.FileSystemObject")
  If objFSO.Fileexists(path) Then objFSO.DeleteFile path
  Set objFSO = Nothing
  objADOStream.SaveToFile path
  objADOStream.Close
  Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing
share|improve this answer
    
This should work. It'll be kinda a pain with XP machines, but its a great help, thanks. –  Jeff F. Jan 17 '12 at 21:23
add comment

If you have wget for Windows on your system path, it's a quick one-liner:

wget http://www.example.com/foo/bar.html

This saves the page locally to the current directory as bar.html.

share|improve this answer
    
I looked into this, I should have probably been more clear on the question. I'd prefer a solution that uses no installation so it can be done on computers across a network if needed. –  Jeff F. Jan 17 '12 at 19:34
add comment

This is not the cleanest solution, but I've used it with success:

  1. Download QtWeb Portable, choose the stand-alone QtWeb.exe

  2. Then, from the command line you can simply run QtWeb.exe -dump_and_quit "url" "file"

  3. QtWeb creates a cache and settings folder, so you may want to remove them:

    rd /s /f QtWebCache
    rd /s /f QtWebSettings
    
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.