473,770 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script to grab web page

drhowarddrfine
7,435 Recognized Expert Expert
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!!!
;)
Nov 19 '08
20 5299
Curtis Rutland
3,256 Recognized Expert Specialist
Working on it....
here's some things I've picked up:

code to download and display html from a website
Expand|Select|Wrap|Line Numbers
  1. url = "http://www.espn.com/main.html" 
  2. set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
  3. xmlhttp.open "GET", url, false 
  4. xmlhttp.send ""
  5. 'this line pops up a dialog and shows the response from the website
  6. WScript.Echo(xmlhttp.responseText)
  7.  
I'll either edit this post with more or add more in new posts
Nov 20 '08 #11
Nepomuk
3,112 Recognized Expert Specialist
I guess this is a VB question then? Should I move it to the VB Forum?

Greetings,
Nepomuk
Nov 20 '08 #12
Curtis Rutland
3,256 Recognized Expert Specialist
Not VB, VBscript. I don't know where it would go....windows might be as good as any place.
Nov 20 '08 #13
KevinADC
4,059 Recognized Expert Specialist
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.
Nov 20 '08 #14
Curtis Rutland
3,256 Recognized Expert Specialist
Well, here you go:

Expand|Select|Wrap|Line Numbers
  1. ' VBScript source code
  2. url = "http://www.google.com" 
  3. path = "C:\dev\vbs\temp.txt"
  4. set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
  5. xmlhttp.open "GET", url, false 
  6. xmlhttp.send ""
  7. Set fso = CreateObject("Scripting.FileSystemObject")
  8. Set txtfile = fso.OpenTextFile(path, 2, True)
  9. txtfile.WriteLine(xmlhttp.responseText)
  10. txtfile.Close
  11. Set txtfile = nothing
  12. set xmlhttp = nothing
  13. Set oWS = WScript.CreateObject("WScript.Shell")
  14. oWS.Run "NotePad.exe /p " + path
  15. set oWS = nothing
  16. set fso = nothing
  17.  
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.
Nov 20 '08 #15
drhowarddrfine
7,435 Recognized Expert Expert
Thanks! I'll give it a try later today and let you know.
Nov 20 '08 #16
Curtis Rutland
3,256 Recognized Expert Specialist
One thing I forgot to mention is that script isn't conditional...i t will print the response, no matter what the response was. You might want to implement some if-then-else logic.

Also, you might want to add this line after line 6:
Expand|Select|Wrap|Line Numbers
  1. xmlhttp.waitForResponse()
  2.  
If you do decide to do it conditionally, you might be interested in this article, which shows all the members and methods of the MSXML2.ServerXM LHTTP object.
Nov 20 '08 #17
Curtis Rutland
3,256 Recognized Expert Specialist
Here, slightly more refined:
Expand|Select|Wrap|Line Numbers
  1. 'define vars
  2. url = "http://bytes.com" 
  3. path = "C:\dev\vbs\temp.txt"
  4. 'instantiate
  5. Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. Set txtfile = fso.OpenTextFile(path, 2, True)
  8. Set oWS = WScript.CreateObject("WScript.Shell")
  9. 'make request
  10. xmlhttp.open "GET", url, false 
  11. xmlhttp.send ""
  12. 'wait for response
  13. xmlhttp.waitForResponse()
  14. 'if status is 200, then it's OK
  15. if xmlhttp.status = 200 then
  16.     txtfile.WriteLine(xmlhttp.responseText)
  17.     txtfile.Close
  18.     'enable this to print
  19.     'oWS.Run "NotePad.exe /p " + path
  20.     'enable this to just display
  21.     oWS.Run "notepad.exe " + path    
  22. else
  23.     'popup bad response, or just omit to end
  24.     WScript.Echo("bad response")
  25. end if
  26. 'destroy objects.  I'm not sure this is necessary
  27. Set txtfile = nothing
  28. Set xmlhttp = nothing
  29. Set oWS = nothing
  30. Set fso = nothing
It's a bit longer because I've included comments.

Now, the program will check that the HTTP status is 200 before proceeding. Right now it will let you know it failed, but if you remove lines 22-24, you will get rid of the popup.

If you want it to print, uncomment 19 and comment 21.

Hope this helps.
Nov 20 '08 #18
drhowarddrfine
7,435 Recognized Expert Expert
Thanks again. I'm floating around right now and that's why I haven't tried it yet.
Nov 20 '08 #19
drhowarddrfine
7,435 Recognized Expert Expert
Success! That's just alright, man. I need to put this on my wife's desktop with the printer to test that part out but Notepad opens the file automatically as is.

The only thing I need to add would be a timer to make it fetch every minute or two. It would be nice if it could print a rendered html page but that can wait.

I'll look later but if you know where the docs are for the timer, I can look it up. Also, if you already know what I should look into for rendering the html for the printer, that would be just great. For now, plain text will be good enough.

Saved me some grief. Thanks again!
Nov 21 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4678
by: R | last post by:
Hi, I have an image loaded on my page that comes from a remote site using JavaScript I'm using... <script src='http://www.whatever.com/JD088?template=GX5'></script> The image loads fine but my page seems to wait for this image to load before
1
4807
by: net | last post by:
I know how to make a page open itself at a certain size and location - I use: <html> <head><script language="Javascript"> window.resizeTo(370,220); window.moveTo(10,10); </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
2
7953
by: mmcc128 | last post by:
When I call this... ------------------------- function funcWinTopJS(){ var s = document.createElement('script'); s.type = "text/javascript"; s.src = "Javascript/Master.asp"; document.documentElement.appendChild(s) } ----------------------------
5
1474
by: P4tryk | last post by:
I load some page using XMLHttpRequest. It has some java script on it. I add this page (using innerHtml) to another but then the java script doesn't run. The main page has <script> function go() { getElementById("replaceContent").innerHtml=httpReq.text; }
3
8265
by: Dustin II. | last post by:
Hi, I have an ASP.NET solution, and the ASPX page I have a form , I want to copy some of the data from that form to the clipboard, I am using the below script the script works fine when I use a normal anchor tag with the onclick event, but I want to be able to use an actual asp control like the hylperlink or linkbutton. I have tried the link button but it gives an error saying Compiler Error Message: BC30456: 'VBScript' is not a member of...
0
1610
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that suggested they had an img tag with src="", I decided to look for instances of "src" and one by one start removing that code to see if it changed anything. Below is the one that, when I removed it, although it broke the flash menus and header, solved...
1
1647
johnbob2010
by: johnbob2010 | last post by:
Is it possible to grab something off a given web page (like page title) and send that along with the form when they click submit? I guess the question is - can I variablize the page title and then pull that variable into the form when submitting? I am using bnbform.cgi on my web host.
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.