Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Saving a webpage to my hard drive through a batch file command  (Read 27845 times)

0 Members and 1 Guest are viewing this topic.

tmerryman

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Saving a webpage to my hard drive through a batch file command
    « on: September 29, 2010, 10:48:49 AM »
    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...

    Teresa

    Linux711



      Mentor

      Thanked: 59
      • Yes
      • Programming Blog
    • Certifications: List
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: Saving a webpage to my hard drive through a batch file command
    « Reply #1 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.
    YouTube

    "Genius is persistence, not brain power." - Me

    "Insomnia is just a byproduct of, "It can't be done"" - LaVolpe

    Salmon Trout

    • Guest
    Re: Saving a webpage to my hard drive through a batch file command
    « Reply #2 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]


    tmerryman

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Saving a webpage to my hard drive through a batch file command
      « Reply #3 on: September 29, 2010, 11:28:36 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!

      Salmon Trout

      • Guest
      Re: Saving a webpage to my hard drive through a batch file command
      « Reply #4 on: September 29, 2010, 11:29:21 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.

      tmerryman

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Unknown
        Re: Saving a webpage to my hard drive through a batch file command
        « Reply #5 on: September 29, 2010, 11:34:12 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.

        Salmon Trout

        • Guest
        Re: Saving a webpage to my hard drive through a batch file command
        « Reply #6 on: September 29, 2010, 12:41:37 PM »
        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"

        « Last Edit: September 29, 2010, 01:02:32 PM by Salmon Trout »

        ghostdog74



          Specialist

          Thanked: 27
          Re: Saving a webpage to my hard drive through a batch file command
          « Reply #7 on: September 29, 2010, 06:33:47 PM »
          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.

          tmerryman

            Topic Starter


            Starter

            • Experience: Beginner
            • OS: Unknown
            Re: Saving a webpage to my hard drive through a batch file command
            « Reply #8 on: September 29, 2010, 09:33:27 PM »
             ;D

            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.

            ghostdog74



              Specialist

              Thanked: 27
              Re: Saving a webpage to my hard drive through a batch file command
              « Reply #9 on: September 29, 2010, 09:46:28 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