Here my elisp code (test by url "http://httpbin.org/html")
(with-current-buffer (url-retrieve-synchronously my-url)
(goto-char (point-min))
(re-search-forward "^$")
(delete-region (point) (point-min))
(setq dom (libxml-parse-html-region (point-min) (point-max)))
(hoge--log-trace "Current buffer content: %s" (buffer-string))
(hoge--log-trace "DOM is: %s" dom)
)
To parse html I use elisp function "libxml-parse-html-region"
The result is:
Current buffer content:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Herman Melville - Moby-Dick</h1>
<div>
<p>
Availing himself ...
</p>
</div>
</body>
</html>
DOM is: nil
如您所见,缓冲区有内容,但elisp函数 libxml-parse-html-region 返回nill,因此DOM对象为NIL。为什么呢?