links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Recipe: Grabbing a page from the Internet
Last updated at 4:47 am UTC on 9 September 2008
You want to retrieve a web page on the Internet for which you have the URL.

"Output a Web page on the Transcript window"
| mimeDoc |
mimeDoc := 'http://www.squeak.org/' asUrl retrieveContents.
Transcript show: mimeDoc content.

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.

Checked with Squeak version 3.10.2: OK.

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.

Squeak version 3.10.2 does not contain the class HtmlParser anymore: you have to load the package Network-HTML through the package universe.
Then it runs fine with 3.10.2.

Also see:

Updated by Hannes Hirzel September 2008