Oladon

more scraper code

Nov 11th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.39 KB | None | 0 0
  1. ;; This one's cool because it finds the correct element based on its parent's parent.
  2. (defun get-title-from-page (page)
  3.   (stp:data
  4.    (car (last (stp:filter-recursively
  5.                #'(lambda (x) (and (typep x 'stp:text)
  6.                                   (stp:attribute-value (stp:parent x) "title")
  7.                                   (equal (stp:attribute-value (stp:parent (stp:parent x)) "class")
  8.                                          "browseLadderCurrentNode")))
  9.                page)))))
  10.  
  11. (defun page-iterate (iterfunc url)
  12.   (let* ((threadbase (ppcre:regex-replace "\\?[^&]+"
  13.                                           (ppcre:regex-replace "&page=(last|first|[0-9]+)"
  14.                                                                url
  15.                                                                "")
  16.                                           ""))
  17.          (page (get-parsed-page (make-new-url threadbase '(("page" . 1)) :paizo t)))
  18.          (title (get-title-from-page page)))
  19.     (values title
  20.             (loop as nextpage = (extract-next-page-number page)
  21.                   append (funcall iterfunc page)
  22.                   while nextpage
  23.                   do (setq page (get-parsed-page (make-new-url threadbase
  24.                                                                (list (cons "page" nextpage))
  25.                                                                :paizo t)))))))
Advertisement
Add Comment
Please, Sign In to add comment