Skip to content

Instantly share code, notes, and snippets.

@hidsh
Last active October 28, 2016 02:13
Show Gist options
  • Save hidsh/c09abb5632739787da9a to your computer and use it in GitHub Desktop.
Save hidsh/c09abb5632739787da9a to your computer and use it in GitHub Desktop.
emacs lisp: cheep example of scraping HTML using wget and regexp
(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