Created
January 17, 2012 02:35
-
-
Save miyamuko/1624211 to your computer and use it in GitHub Desktop.
HTML を txt 形式に変換して取得 #xyzzy
This file contains 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 response-html-text (res) | |
(filter-command "w3m -I Shift_JIS -T text/html" | |
(xhr:xhr-response-text res) | |
:environ '(("LANG" . "ja_JP")))) | |
(defun filter-command (command str &key tmp-file-prefix tmp-file-suffix | |
environ exec-directory) | |
(let ((in-file (make-temp-file-name tmp-file-prefix tmp-file-suffix)) | |
(out-file (make-temp-file-name tmp-file-prefix tmp-file-suffix))) | |
(unwind-protect | |
(progn | |
(alexandria:write-string-into-file str in-file :if-exists :overwrite) | |
(call-process command | |
:input in-file | |
:output out-file | |
:environ environ | |
:exec-directory exec-directory | |
:show :hide :wait t | |
) | |
(alexandria:read-file-into-string out-file)) | |
(flet ((del (file) | |
(delete-file file :if-does-not-exist :skip))) | |
(del in-file) | |
(del out-file))))) | |
(xhr:xhr-get "http://www.hatena.ne.jp/" | |
:key 'response-html-text) | |
"はてな | |
・ ●プロフィール | |
・ Myはてな | |
・ プロフィール検索 | |
・ ヘルプ | |
・ 利用中のサービス | |
・ あなたへのお知らせ | |
(ry | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment