Hi,


Below is the code I created that reads from a text file, a hyperlink, for
example http://yahoo.com. Then creates a URL shortcut.

Is there any way in VBscript to save a web page automatically just like
clicking on "file" and then "save as".

I would like to read a url from a file and save the web page to my local
drive just like clicking "file" and "save as"


Const ForReading = 1

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject ("WScript.shell")
Set oInputFile = oFSO.OpenTextFile("links.txt", ForReading)

arrInputData = Split(oInputFile.ReadAll, vbNewline)

For each strData In arrInputData

if strData = "" then
strNull = strData
else
call createLink(strData)
end if
Next

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

sub createLink(Data)

strLinkName = Data
strfileName = SetFileName(strLinkName)
set oUrlLink = oShell.CreateShortcut(strFileName & ".url" )
'set oUrlLink = oShell.SaveAS(strFileName & ".htm" )
oUrlLink.TargetPath = strLinkName
oUrlLink.Save

end sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function SetFileName(Name)

temp = mid(Name,8)

newString = "$"
oldString = "/"
setFileName = Replace(temp,oldstring,newString,1,-1,1)

end function

Re: Save Web Page with vb script by McKirahan

McKirahan
Thu May 26 15:30:54 CDT 2005

"Keith" <Keith@discussions.microsoft.com> wrote in message
news:F134E190-23E3-4EA5-8810-030423902932@microsoft.com...
> Hi,
>
>
> Below is the code I created that reads from a text file, a hyperlink, for
> example http://yahoo.com. Then creates a URL shortcut.
>
> Is there any way in VBscript to save a web page automatically just like
> clicking on "file" and then "save as".
>
> I would like to read a url from a file and save the web page to my local
> drive just like clicking "file" and "save as"
>

[snip]

Will this help? Watch for word-wrap.

Option Explicit
Const cOUT = "C:\temp\"
Const cURL = "http://www.google.com/"
Const cPAG = "index.html"
MsgBox Fetch(cURL & cPAG,cOUT & cPAG),vbInformation,cVBS

Function Fetch(xURL,xOUT)
On Error Resume Next
Err.Clear
Dim b
With CreateObject("Microsoft.XMLHTTP")
.Open "GET",xURL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile xOUT,2
End With
Fetch = Err.Number = 0
End Function



Re: Save Web Page with vb script by Keith

Keith
Fri May 27 07:28:03 CDT 2005

Thank you for your help! The code works great. Is there any way of saving
the pictures in a web page to the hard disk as well?

Thank you very much!

"McKirahan" wrote:

> "Keith" <Keith@discussions.microsoft.com> wrote in message
> news:F134E190-23E3-4EA5-8810-030423902932@microsoft.com...
> > Hi,
> >
> >
> > Below is the code I created that reads from a text file, a hyperlink, for
> > example http://yahoo.com. Then creates a URL shortcut.
> >
> > Is there any way in VBscript to save a web page automatically just like
> > clicking on "file" and then "save as".
> >
> > I would like to read a url from a file and save the web page to my local
> > drive just like clicking "file" and "save as"
> >
>
> [snip]
>
> Will this help? Watch for word-wrap.
>
> Option Explicit
> Const cOUT = "C:\temp\"
> Const cURL = "http://www.google.com/"
> Const cPAG = "index.html"
> MsgBox Fetch(cURL & cPAG,cOUT & cPAG),vbInformation,cVBS
>
> Function Fetch(xURL,xOUT)
> On Error Resume Next
> Err.Clear
> Dim b
> With CreateObject("Microsoft.XMLHTTP")
> .Open "GET",xURL,False
> .Send
> b = .ResponseBody
> If Err.Number <> 0 Or .Status <> 200 Then
> Fetch = False
> Exit Function
> End If
> End With
> With CreateObject("ADODB.Stream")
> .Type = 1
> .Open
> .Write b
> .SaveToFile xOUT,2
> End With
> Fetch = Err.Number = 0
> End Function
>
>
>

Re: Save Web Page with vb script by McKirahan

McKirahan
Fri May 27 08:08:44 CDT 2005

"Keith" <Keith@discussions.microsoft.com> wrote in message
news:8514E0A3-B3DF-4357-9463-1AAC0B102D02@microsoft.com...
> Thank you for your help! The code works great. Is there any way of
saving
> the pictures in a web page to the hard disk as well?
>
> Thank you very much!

[snip]

Perhaps by walking the DOM (Document Object Model)
looking for "<img>" tags and "<input type='img'>" tags
but that wouldn't find images declared via scripting.

IE has a File + Save As + Web Page
which may save everything as well as resolving the paths.

There are other utilities that save pages / sites.

What is your real purpose?




Re: Save Web Page with vb script by Torgeir

Torgeir
Fri May 27 08:37:48 CDT 2005

Keith wrote:

> Thank you for your help! The code works great. Is there any way
> of saving the pictures in a web page to the hard disk as well?
>
> Thank you very much!
Hi,

You might want to look into the free command line tool wget.exe

wget
http://www.gnu.org/software/wget/wget.html

wget documentation
http://www.gnu.org/software/wget/manual/


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx