它的工作对我来说:
(with-open-stream (stream (ext:open-http
"http://stackoverflow.com/questions/234242424242"
:if-does-not-exist nil))
(format t "~&Stream: ~A~%" stream))
输出:
;; connecting to "http://stackoverflow.com/questions/234242424242"...connected...HTTP/1.1 404 Not Found
;; HTML source of Page not found
Stream: NIL
NIL
有一个延迟,以获得连接,但它的工作原理。
如果页面确实存在:
[7]> (with-open-stream (stream (ext:open-http
"http://stackoverflow.com/questions/36003343/clisp-open-http-example"
:if-does-not-exist nil))
(format t "~&Stream: ~A~%" stream))
;; connecting to "http://stackoverflow.com/questions/36003343/clisp-open-http-example"...connected...HTTP/1.1 200 OK
Stream: #<IO INPUT-BUFFERED SOCKET-STREAM CHARACTER stackoverflow.com:80>
NIL
维基百科我不能让它工作,因为Wikipedia.org它重定向到HTTPS和EXT:OPEN-HTTP
也不能直接处理HTTPS,也不能处理重定向:
这里,如果HTTPS是直接使用:
[10]> (with-open-stream (stream (ext:open-http
"https://en.wikipedia.org/wiki/Common_Lisp"
:if-does-not-exist nil))
(format t "~&Stream: ~A~%" stream))
*** - OPEN-HTTP: "https://en.wikipedia.org/wiki/Common_Lisp" is not an HTTP URL
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [11]> :r1
如果 “https” 开头是 “HTTP” 取代,CLISP不构建一个合适的地址:
[12]> (with-open-stream (stream (ext:open-http
"http://en.wikipedia.org/wiki/Common_Lisp"
:if-does-not-exist nil))
(format t "~&Stream: ~A~%" stream))
;; connecting to "http://en.wikipedia.org/wiki/Common_Lisp"...connected...HTTP/1.1 301 TLS Redirect --> "https://en.wikipedia.org/wiki/Common_Lisp"
;; connecting to "http://en.wikipedia.orghttps://en.wikipedia.org/wiki/Common_Lisp"...
*** - PARSE-INTEGER: substring "" does not have integer syntax at position 0
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [13]>
我想你在这个过程中会遇到其他问题:几乎所有的网站现在都使用HTTPS,CLISP的OPEN-HTTP不支持HTTPS。另外,就我所见,维基百科的文章并不放在* .html文件中,其他文件的路径更复杂。 – mobiuseng
相关:[是否有Wikipedia API?](http://stackoverflow.com/q/627594/124319)。另外,请看[Drakma](http://weitz.de/drakma/) – coredump
感谢迄今为止的回复,但请关注以下问题:如何防止在页面未打开时挂起http存在,无论其网址。一个例子就足够了。 – Leo