1

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.

0

3 Answers 3

2

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
1
  • This should work. It'll be kinda a pain with XP machines, but its a great help, thanks.
    – Jeff F.
    Jan 17, 2012 at 21:23
2

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.

1
  • 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, 2012 at 19:34
0

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
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .