Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read files from a http:// location? 1

Status
Not open for further replies.
Jul 12, 2001
26
AU
I am trying to collate data from various pages (htm, cfm, php) on my company intranet to do some manipulation and re-presentation of the combined data.

I dont have access to the actual data so I am trying to find a way to do this with vbscript/html so that users can use it on their PCs. Long story, company politics, people trying to hoard infomation, usual stuff....anyway...

Basic concept is I want to read a page from a http:// location as a text stream, like you can with the FileSystemObject. Can this be done?

AussieClint
 
Hello AussieClint.

This is one of the ways how you do that. I put the essential in the script below. See how it works out for you.

regards - tsuji

'--------savehttpfile.vbs----/tsuji/--------
Option Explicit

Const httpfile = "Q128/3/45.ASP"
Const savedfile = "q128345.asp"
Const httpAddr =
Code:
"[URL unfurl="true"]http://support.microsoft.com/support/kb/articles"[/URL]

Dim oIE, oHtmlDoc, txt
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True 'Change to False after fully tested
oIE.Navigate httpAddr & "/" & httpfile

Do While (oIE.Busy)
WScript.Sleep 200
Loop

Set oHtmlDoc = oIE.Document.Body.CreateTextRange
txt = oHtmlDoc.HtmlText

Dim fso, oFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso_OpenTextFile(GetPath() & savedfile, 2, True)
oFile.Write txt
oFile.Close
Set oFile = Nothing
Set fso = Nothing

oIE.Quit
Set oHtmlDoc = Nothing
Set oIE = Nothing

Function GetPath()
Dim path
path = WScript.ScriptFullName
path = Left(path, InStrRev(path, "\"))
GetPath = path
End Function
'--------savehttpfile.vbs----/tsuji/--------
 
tsuji,

Works great as a stand alone vbs script but when I place it within a html file I kept getting the error:

Error: Variable is undefined: 'Wscript"
Code: 0

If I removed Option Explicit altogether I received:
Error: Object required: 'Wscript'

I even tried Dim-ing Wscript but still got the error above

If I put Option Explicit within the function I received:
Error: Expected Statement

Removed the file save part portions and changed your code a little... I call the funtion from a html form button.

'-------- hacked by Clint from savehttpfile.vbs----/tsuji/--------
'<!-- '// Hide from other browsers

Option Explicit

Function GetHTTPFile ()

' Const httpfile = &quot;Q128/3/45.ASP&quot;
' Const httpAddr = &quot;
' Testing retrieval of an intranet page
Const httpfile = &quot;index.htm&quot;
Const httpAddr = &quot;
Dim oIE, oHtmlDoc, txt
Set oIE = CreateObject(&quot;InternetExplorer.Application&quot;)

oIE.Visible = False 'Change to False after fully tested
oIE.Navigate httpAddr & &quot;/&quot; & httpfile

Dim i, TimeStart
Do While (oIE.Busy)
' IE/VBScript/HTML doesn't seem to like 'Wscript'
' Wscript.Sleep 500
' Not a nice alternative but what can you do?
For i = 1 To 100000
i = i + 1
Next
Loop

Set oHtmlDoc = oIE.Document.Body.CreateTextRange
txt = oHtmlDoc.HtmlText

Dim ShortenText
'Show just the first 1Kb of the text stream returned for testing purposes.
ShortenText = Left(txt,1024)
alert ShortenText

oIE.Quit
Set oHtmlDoc = Nothing
Set oIE = Nothing
End Function

'// End Hiding -->

'-------- hacked by Clint from savehttpfile.vbs----/tsuji/--------

Do you, or anyone else, have any other ideas on how to simulate sleep as the For loop sends the CPU to 100% which is not real good programming is it now?

Anyway this is a far as I have got so far, provided the dodgy For loop I have in there works on other PCs and not just mine, it MIGHT be alright.

Clint
 
Hello, AussieClint.

Thank you very much for your feedback.

I read your response much earlier, but my mind-set and engagement in other forum and work keep me from answering sooner. But, I think, I have to at least have a signal of appreciation before putting up an alternative resolution of the matter at hand.

I'll come back to your need later, maybe days after. But, first some general opinions.

Sure, you can't dim WScript in browser environment. There is a good chance of <object></object> construction may get it work. But it is not really necessary.

If only you need to simulate Sleep method of WScript, you should look into setTimeout method in dhtml. I think that would make think look better, but, in essense, anything work would do, like what you put there.

One of the reason I conceive a standalone is that because you're in an intranet environment so that you know exactly what you are after. So a standalone would open to you many scripting advantage to program the fetch of pages automatically without supervision. If you do it in a browser environment, sure, it is still a valid desire and should be taken care of.

I'll be back on this days later. Probably using setTimeout would suffice to make your modification look good enough. Keep post and keep me post as well.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top