Page 1 of 1

problem with my project in common lisp

Posted: Mon Dec 21, 2009 6:04 am
by djdebaviere
hello,
I have already posed the same problem on this forum, but I have always the same same problem in my project. My problem is the following: I must extract criticize on films in the Web site www.première.fr.
I have already a function lisp which allows to extract code HTML from the page, but my problem is qu' it is not extract well, because the code html it gives to me is incomplete. you can test and say to me how to arrange this problem.

Code: Select all

(defun connect-to-url (url filename)
    (ext:with-http-input (stream url)
   
        (with-open-file (stream2  filename :direction :output
                                 :if-exists :overwrite
                                 :if-does-not-exist :create )

           (loop for line = (read-line stream nil nil)
               while line
               do (format stream2 line)))))
to run it, write (connect-to-url("URL" " path of the file")

please use http://www.premiere.fr/film/Le-Dernier- ... age)/press like URL

thanks

Re: problem with my project in common lisp

Posted: Mon Dec 21, 2009 7:59 am
by ramarren
The problem is here:

Code: Select all

(format stream2 line)
You are using the line as a format control string. It fails, which you would know if you read the error message, when it encounters the tilde sign, which designates format control directives. To write a sequence to a stream use WRITE-SEQUENCE, or possibly WRITE-LINE to maintain parity with READ-LINE.

Re: problem with my project in common lisp

Posted: Mon Dec 21, 2009 10:05 am
by djdebaviere
thanks!!! it's ok now. I have use write-line and the output is good. the rest is to construct the function which return only the text of critiques. if you have an indication about a function which take a text in input and return a part of this text, help me.

Re: problem with my project in common lisp

Posted: Mon Dec 21, 2009 11:14 am
by ramarren
I would use closure-html to parse the page and plexippus-xpath to extract the appropriate part.

Re: problem with my project in common lisp

Posted: Mon Dec 21, 2009 11:29 am
by djdebaviere
can you give me a small function which use closure-html and plexippus-xpath ?

Re: problem with my project in common lisp

Posted: Mon Dec 21, 2009 11:38 am
by ramarren
There are examples linked from homepages of both of these libraries. Please try to make at least some effort. Also, if you do not know how HTML and parsing work, I would recommend abandoning this project until you do. This is not really something that can or should be explained through a forum.

problem with cl-who

Posted: Wed Dec 23, 2009 5:16 am
by djdebaviere
I have installed cl-who and when I am making the test with the code which are in the home page of cl-who, the running return an error.

Code: Select all

(with-html-output (*http-stream*)
  (loop for (link . title) in '(("http://zappa.com/" . "Frank Zappa")
                                ("http://marcusmiller.com/" . "Marcus Miller")
                                ("http://www.milesdavis.com/" . "Miles Davis"))
        do (htm (:a :href link
                  (:b (str title)))
                :br)))

the message error is

Code: Select all

*** - WITH-HTML-OUTPUT: (*HTTP-STREAM*) does not match lambda list element
       (SYSTEM::VAR STREAM &KEY (SYSTEM::DOCTYPE '*WITH-HTML-OUTPUT-DOCTYPE*)
        (SYSTEM::META '(:HTTP-EQUIV "Content-Type" :CONTENT "text/html"))
        SYSTEM::BASE SYSTEM::COMMENT (SYSTEM::TITLE "untitled")
        (SYSTEM::FOOTER T) SYSTEM::HEAD)


Re: problem with my project in common lisp

Posted: Wed Dec 23, 2009 10:00 am
by nuntius
From the error message, it looks like you're missing the second parameter in the first list to with-html-output; but the current docs indicate its optional?!?
http://weitz.de/cl-who/#with-html-output

Code: Select all

(with-html-output (*standard-output* nil :prologue t)
    (:html (:body "Not much there"))
    (values))