Common Lisp Package: CL-MECHANIZE

README:

About CL-MECHANIZE is a [WWW::Mechanize] work-alike for Common Lisp implemented as a thin wrapper on top of [Drakma].

This package is still in the early stages of development. Please read the source before using; do not expect this to do anything useful.

Getting git clone git://github.com/joachifm/cl-mechanize.git cl-mechanize

Use [QuickLisp] to easily install the dependencies.

Usage

$ lisp  
 
;; Add system definition to the ASDF search path  
(pushnew (merge-pathnames "relative/path/to/cl-mechanize"  
                          (user-homedir-pathname))  
         asdf:*central-registry*)  
 
;; Load system  
(asdf:operate 'asdf:load-op :cl-mechanize)  
(in-package :cl-mechanize-user)  
 
;; Create browser object  
(defvar *browser* (make-instance 'browser)  
 
;; Do a google search  
(fetch "http://www.google.com" *browser*)  
 
(let* ((page (browser-page *browser*))  
       (search-form (car (page-forms page))))  
  (setf (form-inputs search-form)  
        '(("q" . "google")))  
  (submit search-form *browser*)  
 
  (let ((results (browser-page *browser*)))  
    (format t "~A~%" (ppcre:all-matches-as-strings "<title>[a-z].*</title>"  
                                                 (page-content results)))  
    (dolist (link (page-links results))  
      (format t "~A~%" (link-text link)))  
 
    ;; Traverse the DOM  
    (stp:do-recursively (n (page-dom results))  
        ...))) 

FUNCTION

Public

BACK (BROWSER)

Go back in history.

FETCH (URI BROWSER &KEY (METHOD GET) PARAMETERS)

Send a request and fetch the response.

FOLLOW (LINK BROWSER)

Follow a link on the current page.

RELOAD (BROWSER)

Repeat the current request.

SUBMIT (FORM BROWSER)

Submit a form on the current page.

SLOT-ACCESSOR

Public

BROWSER-HISTORY (OBJECT)

A list of visited pages, in chronological order.

SETFBROWSER-HISTORY (NEW-VALUE OBJECT)

A list of visited pages, in chronological order.

BROWSER-PAGE (OBJECT)

The current page object. Updated by FETCH.

SETFBROWSER-PAGE (NEW-VALUE OBJECT)

The current page object. Updated by FETCH.

BROWSER-USER-AGENT (OBJECT)

User-Agent string used by GET.

SETFBROWSER-USER-AGENT (NEW-VALUE OBJECT)

User-Agent string used by GET.

Undocumented

FORM-ACTION (OBJECT)

SETFFORM-ACTION (NEW-VALUE OBJECT)

FORM-INPUTS (OBJECT)

SETFFORM-INPUTS (NEW-VALUE OBJECT)

FORM-METHOD (OBJECT)

SETFFORM-METHOD (NEW-VALUE OBJECT)

FORM-NAME (OBJECT)

SETFFORM-NAME (NEW-VALUE OBJECT)

PAGE-CONTENT (OBJECT)

SETFPAGE-CONTENT (NEW-VALUE OBJECT)

PAGE-DOM (OBJECT)

SETFPAGE-DOM (NEW-VALUE OBJECT)

PAGE-FORMS (OBJECT)

SETFPAGE-FORMS (NEW-VALUE OBJECT)

PAGE-URI (OBJECT)

SETFPAGE-URI (NEW-VALUE OBJECT)

Private

BROWSER-STATUS (OBJECT)

The HTTP status code of the last request.

SETFBROWSER-STATUS (NEW-VALUE OBJECT)

The HTTP status code of the last request.

Undocumented

VARIABLE

Public

*ACCEPT-COOKIES-P*

Accept cookies from visited sites?

*USER-AGENT*

Default User-Agent string.

CLASS

Public

BROWSER

Encapsulates the browser state.

FORM

Represents a form element.

PAGE

Contains the result of fetching a page.