Created
January 17, 2018 22:55
-
-
Save dustinlacewell-wk/b3955560ceae91af3dec1ddadf4d7e5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun amazon-book-data (url) | |
"Return plist of data for book at Amazon URL." | |
(cl-flet ((field (target-field list) | |
(cl-loop for li in list | |
for (field value) = (ignore-errors | |
(-let (((_ _ (_ _ field) value) li)) | |
(list field value))) | |
when (equal field target-field) | |
return (s-trim value)))) | |
(let* ((html (org-web-tools--get-url url)) | |
(tree (with-temp-buffer | |
(insert html) | |
(libxml-parse-html-region (point-min) (point-max)))) | |
(author (esxml-query "span.author a.contributorNameID *" tree)) | |
(title (esxml-query "div#booksTitle h1#title > span *" tree)) | |
(details (esxml-query-all "table#productDetailsTable ul li" tree)) | |
(date (s-replace "– " "" | |
(or | |
;; Printed book | |
(third (esxml-query-all "div#booksTitle h1#title span *" tree)) | |
;; Kindle | |
(field "Publication Date:" details)))) | |
(asin (field "ASIN:" details)) | |
(publisher (replace-regexp-in-string (rx " (" (1+ anything) ")") "" | |
(field "Publisher:" details))) | |
(isbn-10 (field "ISBN-10:" details)) | |
(isbn-13 (field "ISBN-13:" details))) | |
(list :author author :title title :asin asin :publisher publisher :date date | |
:isbn-10 isbn-10 :isbn-13 isbn-13)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment