1.

Solve : Saving a webpage to my hard drive through a batch file command?

Answer»

I have Windows XP and am using Notepad for a batch file:

I have a few webpages that I need to open and then save to my hard drive as an htm document.  How can I write a command to do this?  I am not a programmer; I'm just trying to automate a tedious process for my job.  I can open the web page with my batch file, but that's it.

Another question--Only on one of the web pages,  I have to right click on it and then export to excel.  Is there a  way to write a command to do this too?

Thanks for any suggestions...

TeresaYou should use a vbscript for that.

Have a look at the first code block on this site:
http://www.robvanderwoude.com/vbstech_internet_download.php

You just need to change the first line to the URL you want and then save as vbs.even better, use wget

http://users.ugent.be/~bpuype/wget/

Code: [SELECT]S:\Test>wget http://www.robgendlerastropics.com/index.htm
--2010-09-29 18:22:21--  http://www.robgendlerastropics.com/index.htm
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6883 (6.7K) [text/html]
Saving to: `index.htm'

100%[========================================================================================>] 6,883       40.3K/s   in 0.2s

2010-09-29 18:22:22 (40.3 KB/s) - `index.htm' saved [6883/6883]

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/primer.html
--2010-09-29 18:23:11--  http://www.robgendlerastropics.com/primer.html
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47805 (47K) [text/html]
Saving to: `primer.html'

100%[========================================================================================>] 47,805      44.8K/s   in 1.0s

2010-09-29 18:23:12 (44.8 KB/s) - `primer.html' saved [47805/47805]

Quote from: Linux711 on September 29, 2010, 11:05:53 AM

You should use a vbscript for that.

Have a look at the first code block on this site:
http://www.robvanderwoude.com/vbstech_internet_download.php

You just need to change the first line to the URL you want and then save as vbs.

I'm sorry, I've never used a vbscript before.  Can you be more specific as to what part of the code I need and where to put my url and path to save to?

Thanks for your help! Quote from: tmerryman on September 29, 2010, 11:28:36 AM
I'm sorry, I've never used a vbscript before.  Can you be more specific as to what part of the code I need and where to put my url and path to save to?

Thanks for your help!

I suggest wget. See above.
Quote from: Salmon Trout on September 29, 2010, 11:24:19 AM
even better, use wget

http://users.ugent.be/~bpuype/wget/

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/index.htm
--2010-09-29 18:22:21--  http://www.robgendlerastropics.com/index.htm
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6883 (6.7K) [text/html]
Saving to: `index.htm'

100%[========================================================================================>] 6,883       40.3K/s   in 0.2s

2010-09-29 18:22:22 (40.3 KB/s) - `index.htm' saved [6883/6883]

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/primer.html
--2010-09-29 18:23:11--  http://www.robgendlerastropics.com/primer.html
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47805 (47K) [text/html]
Saving to: `primer.html'

100%[========================================================================================>] 47,805      44.8K/s   in 1.0s

2010-09-29 18:23:12 (44.8 KB/s) - `primer.html' saved [47805/47805]

Thank you for the tip.  If this was my home computer, I would definitely try it.  My work, however, will not allow us to download programs.  I will keep WGet in mind for home use.I have modified the script to accept arguments from the command line. These are 2 in number and they are obligatory. 1. The url of the file you want to download 2. The folder you want to download it to.

To use the script from batch files do this

1. Save it SOMEWHERE on your hard drive. GIVE it a suitable name. I will use the name Downloader.vbs here.

2. run it with CSCRIPT if you want it to behave as a command line program, like this:

cscript //nologo c:\scripts\downloader.vbs "http://www.robgendlerastropics.com/primer.html" "C:\downloads"

I don't know about exporting to Excel, sorry

Code: [Select]
 myURL = wscript.arguments(0)
myPath = wscript.arguments(1)
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
If objFSO.FolderExists( myPath ) Then
    strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
    strFile = myPath
Else
    WScript.Echo "ERROR: Target folder not found."
    wscript.Quit
End If
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

'following line is optional
wscript.echo "Downloading " & myURL

objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )

'following line is optional
wscript.echo "Download complete"

Quote from: tmerryman on September 29, 2010, 11:34:12 AM
My work, however, will not allow us to download programs.

download wget at home and bring to work. If this is a legit task that your boss assigned you, there is no reason to restrict using appropriate tools for the job.  

Well, I just downloaded Wget at home.  It's awesome and so simple!  Thank you for CONVINCING me.  lol  I believe I'll sneak it to work. Quote from: Salmon Trout on September 29, 2010, 12:41:37 PM
Code: [Select]objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )


easier...
Code: [Select]objHTTP.Open "GET", myURL, False
objHTTP.Send
objFile.Write(objHTTP.ResponseText)
objFile.Close


Discussion

No Comment Found