Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Snarf historical prices from ebay... via common lisp
(in-package "CL-USER")
(let ((*print-case* :upcase))
(ql:quickload '(#:fare-memoization #:parse-number
#:optima #:optima.ppcre #:fare-quasiquote-optima
#:drakma #:closure-html)))
(defpackage #:eb
(:use #:common-lisp #:fare-memoization #:parse-number
#:optima #:optima.ppcre
#:drakma #:closure-html))
(in-package "EB")
(defun fetch-price-page (query page-number)
;; for example: (fetch-price-page "macbook air 13" 3)
(let* ((url-template
(url (format nil url-template (url-encode query *drakma-default-external-format*) page-number)))
(parse (http-request url) (closure-html:make-lhtml-builder))))
(memoize 'fetch-price-page)
(defun snarf-prices (page-sxpr)
;; for example: (snarf-prices (fetch-price-page "macbook air 13" 3))
;; They look like this:
;; (:div ((:class "g-b bidsold") (:itemprop "price")) "
;; $18.99")
(let ((result ()))
(labels ((recure (x)
(match x
(`(:div ((:class "g-b bidsold") (:itemprop "price"))
,(ppcre "\\w*\\$([\\d.]+)" price))
(push (parse-number price) result))
((list* (satisfies keywordp) * children)
(map nil #'recure children)))))
(recure page-sxpr)
(nreverse result))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.