Msgbox GetData("http://www.yahoo.com/index.html")
Function GetData(strUrl) 'As String
'Uses POST.EXE from http://www.ericphelps.com/webget/post.zip
'Downloads an http web page and returns a string containing the contents
Dim ts 'As Scripting.TextStream
Dim fs 'As Scripting.FileSystemObject
Dim web 'As Post.clsPost
Dim strWebPage 'As String
Dim strWebSite 'As String
Dim strResource 'As String
If left(strUrl,7) = "http://" Then
strWebSite = Mid(strUrl, 8)
Else
strWebSite = strUrl
End If
If Instr(strWebSite, "/") = 0 Then strWebSite = strWebSite & "/"
strResource = Mid(strWebSite, Instr(strWebSite, "/"))
strWebSite = Left(strWebSite, Instr(strWebSite, "/") - 1)
Set web = CreateObject("Post.clsPost")
web.DataTimeout = 120
web.SocketTimeout = 60
'Get it! (Force string so VBS doesn't try to pass a string-type variant instead)
strWebPage = web.GetHeader(Cstr(strWebSite), Cstr(strResource))
'Check to see if we got content
If Len(Mid(strWebPage, Instr(strWebPage, vbCrlf & vbCrlf) + 4)) = 0 Then
If InStr(strWebPage, "Location:") <> 0 Then
'Recursive follow of redirect. Trim the new location out of the response
strWebPage = Mid(strWebPage, InStr(strWebPage, "Location:") + 9)
strWebPage = Trim(strWebPage)
strWebPage = Left(strWebPage, InStr(strWebPage, vbCr) - 1)
strWebPage = GetData(strWebPage)
Else
strWebPage = ""
End If
Else
'Remove the header
strWebPage = Mid(strWebPage, Instr(strWebPage, vbCrlf & vbCrlf) + 4)
End If
GetData = strWebPage
End Function
Function GetData(strUrl) 'As String
'Uses MSINET.OCX from http://activex.microsoft.com/controls/vb5/msinet.cab
'Requires a Microsoft developer's license. May require license fix from
'ftp://ftp.microsoft.com/softlib/mslfiles/vbc.exe
'Returns a string containing the contents of a web page
Dim web 'As InetCtls.Inet
Dim strWebPage 'As String
Set web = CreateObject("InetCtls.Inet")
web.RequestTimeout = 60
strWebPage = web.OpenURL(Cstr(strUrl))
GetData = strWebPage
End Function
Function GetData(strUrl) 'As String
'Uses WGET.EXE from http://www.geocities.com/heiko_herold/
'to return a string containing the contents of an http web page
Dim ts 'As Scripting.TextStream
Dim wsh 'As Wscript.Shell
Dim fs 'As Scripting.FileSystemObject
Dim fil 'As Scripting.File
Dim strWebPage 'As String
Dim strTempFile 'As String
Const ForReading = 1
Const ForWriting = 2
Const TemporaryFolder = 2
Set fs = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("Wscript.Shell")
strTempFile = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder), fs.GetBaseName(Wscript.ScriptFullName) & ".tmp")
Set ts = fs.CreateTextFile(strTempFile, True)
ts.Close
Set fil = fs.GetFile(strTempFile)
wsh.Run "wget.exe -O " & fil.ShortPath & " " & strUrl, 0, True
Set ts = fs.OpenTextFile(strTempFile, ForReading, True)
strWebPage = ts.ReadAll
ts.Close
fil.Delete True
GetData = strWebPage
End Function
Function GetData(strUrl) 'As String
'Uses Internet Explorer to return a string containing the
'contents of an http or ftp web page
Dim web 'As InternetExplorer.Application
Dim doc 'As InternetExplorer.Document
Dim strWebPage 'As String
Set web = CreateObject("InternetExplorer.Application")
web.Navigate strUrl
Do While web.Busy
Loop
On Error Resume Next
Set doc = Nothing
Do Until Not doc Is Nothing
Set doc = web.Document
Loop
strWebPage = doc.body.OuterHTML
GetData = strWebPage
End Function
Function GetData(strUrl) 'As String
'This is not my original script, but is one of the public domain
'scripts included as a sample with PrimalSCRIPT. Credit for the
'script is attributed to "Eric K." and "Michael Harris". This
'script does a BINARY download. I've modified it here to suit
'my purposes.
Dim xml 'As Microsoft.XMLHTTP
Dim strWebPage 'As String
Dim strTemp 'As String
Dim lngCounter 'As Long
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", strUrl, False
xml.Send
strTemp = xml.ResponseBody
Set xml = Nothing
For lngCounter = 0 to UBound(strTemp)
strWebPage = strWebPage & Chrw(Ascw(Chr(Ascb(Midb(strTemp,lngCounter+1,1)))))
Next
GetData = strWebPage
End Function
Function GetData(strUrl) 'As String
'Uses WEBGET.EXE from http://www.ericphelps.com/webget/get.zip
'Downloads an http web page and returns a string containing the contents
Dim web 'As WebGet.Web
Dim sRxData 'As String
Set web = CreateObject("WebGet.Web")
If Left(strUrl, 7) <> "http://" Then strUrl = "http://" & strUrl
web.URL = strUrl
sRxData = web.GetText
GetData = sRxData
End Function