elisp是否具有获取网址和目的地的功能,并将该网址从互联网上下载?
我发现url-retrieve
和url-retrieve-synchronously
但url-retrieve
接受回调,url-retrieve-synchronously
将所有内容放入缓冲区。还有什么更简单的吗?
答案 0 :(得分:25)
试试url-copy-file
。其描述如下:
url-copy-file是`url-handlers.el'中自动加载的Lisp函数。 (url-copy-file url newname& optional ok-if-already-exists keep-time)
将网址复制到新名称。两个args必须是字符串。 如果文件newname已存在,则表示“文件已存在”错误, 除非第三个参数ok-if-already-exists被提供且非nil。 如果newname已经存在,则作为第三个arg的数字表示请求确认。 这是与M-x交互使用时发生的情况。 第四个arg保持时间非零意味着给新文件相同 最后修改时间为旧时间。 (这仅适用于某些系统。) 前缀arg使保持时间非零。
答案 1 :(得分:8)
显然url-copy-file
是最好的选择,但对于更具冒险精神的Emacs黑客,我建议这样的话:
(require 'url)
(defun download-file (&optional url download-dir download-name)
(interactive)
(let ((url (or url
(read-string "Enter download URL: "))))
(let ((download-buffer (url-retrieve-synchronously url)))
(save-excursion
(set-buffer download-buffer)
;; we may have to trim the http response
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(forward-char)
(delete-region (point-min) (point))
(write-file (concat (or download-dir
"~/downloads/")
(or download-name
(car (last (split-string url "/" t))))))))))
答案 2 :(得分:4)
(w3m-download "http://www.gnu.org/index.html")
答案 3 :(得分:4)
http://steloflute.tistory.com/entry/Emacs-Lisp-urlretrieve
; synchronously
(defun get-url (url)
(with-current-buffer (url-retrieve-synchronously url) (buffer-string)))
(print (get-url "http://www.gnu.org"))
; asynchronously
(defun print-url (url)
(url-retrieve url (lambda (a) (print a))))
(print-url "http://www.gnu.org")
检索网址| http://www.gnu.org/software/emacs/manual/html_node/url/Retrieving-URLs.html
当前缓冲区| http://www.gnu.org/software/emacs/manual/html_node/elisp/Current-Buffer.html