ScriptSpot

Forum topic · General Scripting

OpenFile() from "http://" address

By sTeapot · 2011-06-21

Description

Hi,

Does anyone know if there is a way to use openfile() for a web address starting with "http://". I get undefined all the time. Any html is just an ascii file, so I guess the address is the problem here.
I don't want to view it, I just want to read it and search for some strings.
Any ideas?

Comments (4)

br0t · 2011-06-22

that looks like a real nice breakdown how to access data from the web, thanks!

sTeapot · 2011-06-21

.. nevermind, I figured it out :)
-> ActiveXControl

use .Net WebClient

Anubis · 2011-06-21

OpenFile is for local files.
Here is 3 variants i have in mind -

-- ref WebClient object:
netWC = (dotNetObject "System.Net.WebClient")

--//variant 1 - download the file:
urlFile = "http://project3d.narod.ru/rss/rss.xml"
destFile = "C:\\temp\\" + (filenameFromPath urlFile)
netWC.downloadFile urlFile destFile

--//variant 2 - download as string:
stream = (netWC.DownloadString urlFile) as stringStream

--//variant 3 - read as stream from the server:
stream = netWC.OpenRead urlFile
source = if stream.CanRead then (
	sr = dotNetObject "System.IO.StreamReader" stream
	retStr = sr.ReadToEnd(); sr.Dispose()
	retStr
) else ""
stream.Close()
free stream

Cheers!

sTeapot · 2011-06-21

Sweet!
Thanks for the alternatives!
Didn't see your post when I replied to myself