2010/10/27

CL-MECHANIZE 続きの続き

@snmsts さんがやってくれたので、昨日の続き。 @snmsts さんありがとうございます。

で drakma:http-request はちゃんと文字列を返してくれるようになったけど、 sb-thread:with-mutex でエラーになるので、 sb-thread:with-recursive-lock にしようか迷いながら、 sb-thread:with-mutex を削除。


diff --git a/cl-mechanize.lisp b/cl-mechanize.lisp
index f40fbf0..5aea76f 100644
--- a/cl-mechanize.lisp
+++
b/cl-mechanize.lisp
@@ -134,11 +134,10 @@ Handles cookies and history automatically."
(defun submit (form)
"Submit a form."
(declare (type form form))
- (sb-thread:with-mutex (*state-mutex*)
- (fetch (puri:merge-uris (form-action form)
- (page-uri *page*))
- :method (form-method form)
- :parameters (form-inputs form))))
+ (fetch (puri:merge-uris (form-action form)
+ (page-uri *page*))
+ :method (form-method form)
+ :parameters (form-inputs form)))

(defun follow (link)
"Follow a link."

ようやく動いたけど、どうも挙動が怪しい。 (fetch "http://www.google.com") のリンクが印字されるんだよなぁ。

(eval-when (:compile-toplevel :load-toplevel :execute)
(require :cl-mechanize)
(require :flexi-stream-jp))

(defpackage :try-cl-mechanize
(:use :cl :cl-mechanize))

(in-package :try-cl-mechanize)

(setf drakma:*drakma-default-external-format* :utf-8)

;; Do a google search
(progn
(fetch "http://www.google.com")
(let* ((page (get-page))
(search-form (car (page-forms page))))
(setf (form-inputs search-form)
'(("q" . "Common Lisp エイリアン")))
(submit search-form)
(format t "~A~%" (ppcre:all-matches-as-strings "<title>[a-z].*</title>"
(page-content page)))
(dolist (link (page-links page))
(format t "~A~%" (link-text link)))))

;; Traverse the DOM
(stp:do-recursively (n (page-dom (get-page)))
(print n))

0 件のコメント: