Arc Forumnew | comments | leaders | submitlogin
1 point by skenney26 5654 days ago | link | parent

I've been looking through stefano's code. It looks like something like this should work...

  (let (i o) (connect-socket url* 80)
    (disp (readline i)))
... or something like that, but I haven't gotten it to work. Usually I get an error or a return value of nil.


3 points by stefano 5653 days ago | link

With http-get loaded this macro should do the job. You could also have a look at xml.arc to parse xhtml pages.

  (mac w/url (var url . body)
    `(let ,var (cadr (get-request (str->url ,url)))
       ,@body)))

-----

1 point by skenney26 5653 days ago | link

Awesome, that's exactly what I needed.

I'm not familiar with how to use xml.arc but this is what I came up with for finding the links on a page:

  (def find-links (str)
    (with (start 0 acc nil)
      (whilet p (posmatch " href=" str start)
        (= start
           (+ p (if (in (str (+ p 6)) #\' #\") 7 6)))
      (push (cut str start (pos [in _ #\' #\" #\> #\space] str start))
            acc))
      (rev acc)))

  (w/url u "http://www.google.com/"
    (find-links u))

-----