Link to home
Create AccountLog in
Avatar of sdatla
sdatla

asked on

Need help in launching URL in VBScript and save the contents to a file

I need to launch URL using vbscript and save the contents of URL to a text file. I don't want to copy the clipboard to copy and paste
the content as it takes long time.
I tried using the below code to launch URL. it doesn't work. Do i need some xml version MSXML to be installed to launch the web page?
cURL = "http://www.google.com"
Dim objXML
'*  Set objXML = CreateObject("MSXML2.XMLHTTP")
   Set objXML = CreateObject("Microsoft.XMLHTTP")
       objXML.Open "GET", cURL, False
       objXML.Send
       strXML = objXML.ResponseText
   Set objXML = Nothing

I don't know how to save the web page to a text file. Please help me.
Avatar of Brendan M
Brendan M
Flag of Australia image


Dim objFileSystem, objOutputFile
Dim strOutputFile

' generate a filename base on the script name
strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)

With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://www.rgagnon.com/howto.html", False
  .send
  objOutputFile.WriteLine .responseText
End With

objOutputFile.Close

Set objFileSystem = Nothing

WScript.Quit(0)

Open in new window

Avatar of sdatla
sdatla

ASKER

I tried using this code.

At line 12, i got Access denied. (msxml3.dll)

i attached the screenshot. Please help.

Thank you.
msxml3-error.bmp
sorry the screenshot is blank?
Avatar of sdatla

ASKER

This is the error i got.

Script: test. vbs
Line:12
Char 3
Error: Access Denied
Error: 80070005
Source:msxml3.dll
Avatar of sdatla

ASKER

There was some info on Google about this error code. It said it is because of the corrupted registry files and recommed solution is to install some Repair utility. I tried installling that and in order to fix it, it asked me to purchase the license. I could not go further on that. I am using IE8 browser.
I tested on another machine which has IE8 and it has got the same error. I don't think it is something with the corrupted files. Please help.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Brendan M
Brendan M
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of sdatla

ASKER

Thanks for your reply. I could run the script.

I have one question. When the script ran, it didn't launch the URL for me to see which URL it ran, but It did write the source to the file. (Thank you).  Does the "Get" method launch the URL? I could get the output. It wrote the source code to the text file (With the html tags and functions). I want to write the web page content (the content on the page which appears in plain text)  to the file. Can you help me with that?

Thank you.
It could be done, but it probably wont turn out how you would want, as html tells the webbrowser how to display the page.

can you give an example url that you would like?
Avatar of sdatla

ASKER

I have one intranet URL but the url would be anything (http://www.w3schools.com).

I can manage with that or remove the tags. Just trying to see if i can get the plain text. I am fine with it.

i will accept the solution once i get reply from you.
it would probably be best to leave the html as removing it can make the file all jumbled