Solved

VBScript: HttpRequest to a file

Posted on 2011-03-20
8
742 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now