RE: Getting the contents of a web page
"Roger Corman" <[email protected]> Sat, 5 Apr 2003 20:41:15 -0800
| Newsgroups | gmane.lisp.corman |
|---|---|
| Message-ID | <00cb01c2fbf6$c1d762c0$0300a8c0@roger> |
Chris Double's socket code works pretty well for this (which is
included).
This should get you started (adapted from one of Chris's examples):
(require 'sockets)
(in-package :sockets)
(defun web-page-contents (host resource &optional (port 80))
(with-client-socket (s :host host :port port)
(write-socket-line s (format nil "GET ~A HTTP/1.0" resource))
(write-socket-line s "")
(let ((content-length 0))
(loop as line = (read-socket-line s)
while (and line (> (length line) 0))
do
(when (equal
(string-upcase (subseq
line 0 (search ":" line)))
"CONTENT-LENGTH")
(setq content-length
(parse-integer line
:start (+ (search ":" line) 1)))))
;; Read contents
(read-socket s content-length))))
As you can see, the URL parsing is not done by this--you have to
separate the server, resource and possibly the port (if not default port
80) from the URL yourself.
Example:
(web-page-contents "www.cormanlisp.com" "/") ;; get root
page
(web-page-contents "www.cormanlisp.com" "/license.html") ;; get
license page
Roger
-----Original Message-----
From: JP Massar [mailto:[email protected]]
Sent: Saturday, April 05, 2003 1:27 PM
To: [email protected]
Subject: [cormanlisp] Getting the contents of a web page
Is there the equivalent of the Allegro function
WEB-PAGE-CONTENTS <url>
which returns the page source as a string
somewhere buried in Corman or its modules?
For bonus points anyone the equivalent, if it exists, for Lispworks?
(Yes, I've tried apropos, nothing popped up as obviously
correct)
Thanks!
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/xaxhjB/hdqFAA/VygGAA/SyjtlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/