Hi,

The code below is a little program implemented as a compilable functor that I wrote to return my routers current IP address by connecting to http://checkip.dyndns.org.

The URL is opened as a read-only 'file' in line 8. This should demonstrate how to actually open the web address for reading.

Unfortunately, in my case, the parsing I required was very simple so I just read a fixed length list from the site and parsed it using 'String.token'. I can't remember the exact output from the site but looking at my code it obviously involved a ':' and '<' character. It's not the most elegant solution but it was all that was required for this particular program. I believe Wolfgang Meyer has already pointed you to the XML parser available. I did start work on an Oz version of Python's 'BeautifulSoup' extension but I got diverted onto other work. Perhaps I might get back to that soon...

Hope this helps!

Regards

Mark R

%%Program to get a user's IP address as seen from the internet.
%%Eg. A routers internet IP address.
%%The program relies on the following web address
%%http://checkip.dyndns.org
%%Copyright Mark Richardson 2008

1 functor
2 import
3    Open(file)
4    System
5    URL(make)
6    Application
7 define
8 F={New Open.file init(url:{URL.make 'http://checkip.dyndns.org/'} flags:[read])} 9 Output={VirtualString.toString "GetIp - version 0.1\nCopyright 2008 Mark Richardson\nAttempting to contact http://checkip.dyndns.org\n\nCurrent external IP address is:"#{String.token {String.token {F read(list:$ size:105)} &: _ $} &< $ _}#"\n\n"}
10   {System.printInfo Output}
11   {Application.exit 0}
12 end

Alan Géraud wrote:
Good morning!
I have a problem with an implementation in Oz language. In fact i want to get access to a web page and i don't know which function to use, and then parse it.
i'm just a beginner in oz programming.
please, i need help.


------------------------------------------------------------------------
Windows 7 : Simplifiez votre quotidien. Trouvez le PC qui vous convient. <http://windows.microsoft.com/shop>
------------------------------------------------------------------------

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users


--
Mark Richardson MBCS
Research Assistant
University of Teesside, UK
Email: [email protected]
      [email protected]
Skype: mark.richardson.

_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to