Recipe: Grabbing a page from the Internet
Last updated at 6:08 am UTC on 11 November 2006
Problem
You want to retrieve a web page on the Internet for which you have the URL.
Solution
"Output a Web page on the Transcript window"
| mimeDoc |
mimeDoc := 'http://www.squeak.org/' asUrl retrieveContents.
Transcript show: mimeDoc content.
Discussion
asUrl takes a string and converts it to an URL. Recipe: Grabbing a page from the Internets are represented as concrete subinstances of Url (one for each protocol). retrieveContents asks a Url to retrieve its contents and return a MIMEDocument. A MIMEDocument contains the actual data along with a MIME content-type; content will return the data.
Showing the page in its own TwoWayScrollPane.
| mimeDoc |
urlString := 'http://www.squeak.org/'.
mimeDoc := urlString asUrl retrieveContents.
StringHolder new textContents: mimeDoc content withSqueakLineEndings; openLabel: urlString.
Or popping up an ObjectExplorer on the parsed HTML document
| mimeDoc |
urlString := 'http://www.squeak.org/'.
mimeDoc := urlString asUrl retrieveContents.
(HtmlParser parse: mimeDoc content) explore
The same in one line
(HtmlParser parse: 'http://www.squeak.org/' asUrl retrieveContents content) explore
For more details, browse classes Url and MIMEDocument in the system.
Also see:
Updated by Hannes Hirzel 05-Feb-2002