Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript: HttpRequest to a file

Posted on 2011-03-20
8
Medium Priority
?
765 Views
Last Modified: 2012-05-11
Hi there,

I need to have a VBscript that sends an HttpRequest and dumps the text to a file.

This VBScript will be started from a batch file as the following command line:
cscript //nologo "WebsiteMonitor.vbs" "http://tools.oratory.com/altcodes.html" "WebsiteMonitor.txt"

The tools.oratory.com web page was use for test purposes only.

Here, as a result, the output file "WebsiteMonitor.txt", would contain the text (with the french accents) contained in tools.oratory.com/altcodes.html

Please provide a working script, not a references to make it work.

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35177749
Can you state the purpose can it be saved as html itself?
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35178355
Yes, it can be saved in HTML

Thanks,
Rene
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35178421
Try the following code...

for the html file to be created mention the full path

cscript //nologo "WebsiteMonitor.vbs" "http://tools.oratory.com/altcodes.html" "c:\WebsiteMonitor.html"
Set objArgs = WScript.Arguments
url=objargs(0)
html_file=objargs(1)

'***********************************************************************
On Error Resume Next

Dim xmlhttp : Set xmlhttp = CreateObject ("msxml2.xmlhttp.3.0")
xmlhttp.open "get", url, False
xmlhttp.send

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objfso.CreateTextFile html_file,True
    Set writefile= objfso.OpenTextFile(html_file,2)
    writefile.Write xmlhttp.responseText
    writefile.Close

'Clear all memory variables

Set xmlhttp = Nothing
Set objEmail= Nothing

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:ReneGe
ID: 35178996
The strange thing, is that it does not work with the test website I suggested. However, it works on all other websites I tested that contains french caracters.

So I googled "alt codes" and tried with other sites that displays alt codes. It did not work with any of these sites.

Could it be that "Alt Codes websites" contains "alt codes" that stops the script from working?
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35179157
Try the following code

regards
Prashanth
Set objArgs = WScript.Arguments
url=objargs(0)
html_file=objargs(1)

'***********************************************************************
On Error Resume Next

Dim xmlhttp : Set xmlhttp = CreateObject ("msxml2.xmlhttp.3.0")
xmlhttp.open "get", url, False
xmlhttp.send

Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile html_file
oStream.Close

'Clear all memory variables

Set xmlhttp = Nothing
Set objEmail= Nothing

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35179217
Now, nothing is outputed to the files.
0
 
LVL 12

Accepted Solution

by:
prashanthd earned 2000 total points
ID: 35179306
Typo error, replace line no 15 with following and test

oStream.Write xmlhttp.responseBody
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35180621
It works very well.

Thanks prashanthd!

Cheers,
Rene
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question