Last active
October 28, 2016 02:13
-
-
Save hidsh/c09abb5632739787da9a to your computer and use it in GitHub Desktop.
emacs lisp: cheep example of scraping HTML using wget and regexp
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 scrape-from-uri (uri re) | |
(let ((ssl-opt (if (string= (substring uri 0 5) "https") "--no-check-certificate" ""))) | |
(with-temp-buffer | |
(switch-to-buffer (current-buffer)) ; debug | |
(call-process "wget" nil t nil "-q" "-O" "-" "-U" "Mozilla/5.0" ssl-opt uri) | |
(goto-char (point-min)) | |
(re-search-forward re nil t) | |
(match-string 1)))) | |
; test | |
;(scrape-from-uri "https://www.google.co.jp/search?q=nintendo+3ds" "<title>\\([^<>]+\\)</title>") | |
;=>"nintendo 3ds - Google 検索" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment