Script to grab web page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    Script to grab web page

    I have a web application that will generate a web page and tuck it in a top secret location on the server. I need a Windows XP box to be able to run a program in the background to check to see if the page is there and fetch this page from the server and print it on the Windows printer. It should poll the server every minute or two.

    XP Pro is available but would rather it run on XP Home. The page is located in an unpublished area of the server but does not need to be secured. The page would be html, text only for now, but I could tolerate plain text (for now).

    If this was a 'nix box, I could use a shell script and wget and write a script in 10 lines to do this but none of that is installed on Windows. I reeeaaaallly don't want to have to install anything on the Windows box to do that so I'm wondering if there is an equivalent scripting method that would work with something in Windows and do what I want.

    From googling a little, all I see is everything done in VB. I reeeaallly don't want to have to learn VB to do what should be a trivial task, and I'm concerned what I would have to download and install just to develop the code.

    Can someone give me a clue, please?
    Send me the code.
    It's URGENT!!!
    ;)
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Luckily, MS seems to have realised how powerful the unix shell and how lame theirs is. So, they developed the Windows PowerShell which can downloaded for free. OK, you preferred to install nothing, but I think you may want to change your mind for this. The syntax seems to be quite similar to that in bash, so you should find your way around it quickly.
    Originally posted by drhowarddrfine
    Send me the code.
    It's URGENT!!!
    ;)
    OK, because it's you. Here are two versions of wget for the PowerShell: simple version and more powerful version. ^^

    Greetings,
    Nepomuk

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      **sigh**
      More to learn.

      Or not.

      I saw the PowerShell thing yesterday and thought it was an editor. I also see it's hooked in with .NET and you must(?) learn some of the .NET stuff.

      The decision is between learning that or installing Windows on a box, downloading the PlatformSDK and coding in Win32, something I have experience with. I don't want to do either but feel more comfortable doing the latter. I'm also concerned that forcing customers to install PowerShell just to run my little script would be highly inconvenient.

      And I'm looking at 10 lines of code in 'nix and I'd be done right now. People wonder why I feel the way I do about Windows.

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        I just thought some more and remembered Cygwin. It basically gives you a unix-like command line for Windows and it runs bash (and some other shells too), so no need for relearning. However you'd still have to install something.

        Is there a way around that? Maybe - with win-bash for example, which is a port of an old version of bash. You don't have to install it, just copy the exe somewhere. If you want to load it from the windows command line, put the place that exe is in in the Path variable. I've never tested it, but it sounds good, right?

        There are similar projects like GNU BASH For Windows, GNU utilities for Win32, MinGW and probably many more. I don't know which of these have to be installed and which don't, but maybe you can tell us more soon? ^^

        Oh, maybe just downloading wget for Windows will do the job too - it all depends on the script you want to write.
        Originally posted by drhowarddrfine
        And I'm looking at 10 lines of code in 'nix and I'd be done right now. People wonder why I feel the way I do about Windows.
        Believe me, I can understand your frustration. Since I've been using Linux, I feel very limited every time I use a Windows machine.

        Greetings,
        Nepomuk

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          Yes, I've used cygwin but there, again, I'd have to install it. I'm also wondering if it might conflict with Win networking.

          Does anyone happen to know if VB.NET is installed by default with .NET or Windows itself? I'm wondering if I might find someone to write this simple script for me.

          As I was typing this, I was thinking whether Firefox and Prism (or is it Weave?) could do this. It interacts with web apps and is standalone from the browser and a smaller footprint. But I don't know if it could print. Of course, then I'd have to learn how to use it but that would be far more useful than VB.NET.

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #6
            Originally posted by drhowarddrfine
            Does anyone happen to know if VB.NET is installed by default with .NET or Windows itself? I'm wondering if I might find someone to write this simple script for me.
            As I understand it (and I don't know much about .NET) all .NET languages are translated to a common byte code language, so it doesn't matter which .NET language a program was written in, if the Framework is installed, you can run it.

            Greetings,
            Nepomuk

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              I know that but is vb.net installed automagically on all systems?

              Right before I went to bed, I saw an article talking about VBScript. I'm wondering if that's on all systems. I don't think it needs .NET and it looks basic enough.

              Comment

              • AmberJain
                Recognized Expert Contributor
                • Jan 2008
                • 922

                #8
                Hello,

                Originally posted by drhowarddrfine
                Right before I went to bed, I saw an article talking about VBScript. I'm wondering if that's on all systems. I don't think it needs .NET and it looks basic enough.
                I dont know much about VB or .NET but I am sure that VBscript is available on all the systems and it doesnot needs .NET.

                In wikipedia's words:

                Originally posted by wikipedia
                VBScript is installed by default in every desktop release of Microsoft Windows since Windows 98,[1] and may or may not be included with Windows CE depending on the configuration and purpose of the device it is running on.
                Originally posted by wikipedia
                A VBScript script must be executed within a host environment, of which there are several provided on a standard install of Microsoft Windows (Windows Script Host, Internet Explorer). Additionally, The VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script control (msscript.ocx).
                Hope this helps....
                AmbrNewlearner

                Comment

                • Curtis Rutland
                  Recognized Expert Specialist
                  • Apr 2008
                  • 3264

                  #9
                  If you're into scripting, VBScript would be the way to go. Probably won't be all that difficult, but I'm not a scripting kind of person.

                  On the other hand, if you're a programmer, and you have Visual Studio, you could write a windows service pretty quickly. Then you wouldn't have to worry about scheduling the script to run.

                  From what I have experience with, the second is easier, but if you don't have a working knowledge of .NET, (which should be installed in either SP2 or SP3 by default) then I would go with the first.

                  Comment

                  • drhowarddrfine
                    Recognized Expert Expert
                    • Sep 2006
                    • 7434

                    #10
                    OK, so now I know VBScript is what I can use. Back to the original question:
                    I have a web application that will generate a web page and tuck it in a top secret location on the server. I need a Windows XP box to be able to run a program in the background to check to see if the page is there and fetch this page from the server and print it on the Windows printer. It should poll the server every minute or two. XP Pro is available but would rather it run on XP Home. The page is located in an unpublished area of the server but does not need to be secured. The page would be html, text only for now, but I could tolerate plain text (for now).

                    Comment

                    • Curtis Rutland
                      Recognized Expert Specialist
                      • Apr 2008
                      • 3264

                      #11
                      Working on it....
                      here's some things I've picked up:

                      code to download and display html from a website
                      Code:
                      url = "http://www.espn.com/main.html" 
                      set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
                      xmlhttp.open "GET", url, false 
                      xmlhttp.send ""
                      'this line pops up a dialog and shows the response from the website
                      WScript.Echo(xmlhttp.responseText)
                      I'll either edit this post with more or add more in new posts

                      Comment

                      • Nepomuk
                        Recognized Expert Specialist
                        • Aug 2007
                        • 3111

                        #12
                        I guess this is a VB question then? Should I move it to the VB Forum?

                        Greetings,
                        Nepomuk

                        Comment

                        • Curtis Rutland
                          Recognized Expert Specialist
                          • Apr 2008
                          • 3264

                          #13
                          Not VB, VBscript. I don't know where it would go....windows might be as good as any place.

                          Comment

                          • KevinADC
                            Recognized Expert Specialist
                            • Jan 2007
                            • 4092

                            #14
                            write a DOS/batch file and run it using a task. Nothing to install but you will have to learn batch file scripting. I guess what you would have to figure out is how to fetch an internet document using the windows commands, possibilites are Ftp and telnet but maybe there is a wget type of command. Then use the Print command to print it.

                            Comment

                            • Curtis Rutland
                              Recognized Expert Specialist
                              • Apr 2008
                              • 3264

                              #15
                              Well, here you go:

                              Code:
                              ' VBScript source code
                              url = "http://www.google.com" 
                              path = "C:\dev\vbs\temp.txt"
                              set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
                              xmlhttp.open "GET", url, false 
                              xmlhttp.send ""
                              Set fso = CreateObject("Scripting.FileSystemObject")
                              Set txtfile = fso.OpenTextFile(path, 2, True)
                              txtfile.WriteLine(xmlhttp.responseText)
                              txtfile.Close
                              Set txtfile = nothing
                              set xmlhttp = nothing
                              Set oWS = WScript.CreateObject("WScript.Shell")
                              oWS.Run "NotePad.exe /p " + path
                              set oWS = nothing
                              set fso = nothing
                              Paste this into a text file named whatever.vbs. Then you should be able to double-click it and run it. Make sure to change the url and path.

                              I learned something new today...this was the first VBScript "program" I wrote. What this will do is get the HTML response from a website, create a text file, copy the response to file, then print it. It's pretty rough, and an experienced scripter could probably do worlds better, but it's a start.

                              Comment

                              Working...