unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* To fetch URL, extract <title> element?
@ 2020-11-11  9:28 Jean Louis
  2020-11-11 15:27 ` Michael Heerdegen
  0 siblings, 1 reply; 6+ messages in thread
From: Jean Louis @ 2020-11-11  9:28 UTC (permalink / raw)
  To: GNU Emacs Help

What is the standard built-in way to fetch the http[s] URL?

I need to get string to parse <title> and I think something like this
below:

(setq a
      (with-temp-buffer
	(url-retrieve "https://www.gnu.org" 'identity)
	(buffer-string)))


When researching `eww' I find this function here, which is chunk that
makes sure of parsing and punny code in the URL. I do not find it
useful as I cannot easily fetch URL without thinking of those details.

;;;###autoload
(defun eww (url &optional arg buffer)
  "Fetch URL and render the page.
If the input doesn't look like an URL or a domain name, the
word(s) will be searched for via `eww-search-prefix'.

If called with a prefix ARG, use a new buffer instead of reusing
the default EWW buffer.

If BUFFER, the data to be rendered is in that buffer.  In that
case, this function doesn't actually fetch URL.  BUFFER will be
killed after rendering."
  (interactive
   (let ((uris (eww-suggested-uris)))
     (list (read-string (format-prompt "Enter URL or keywords"
                                       (and uris (car uris)))
                        nil 'eww-prompt-history uris)
           (prefix-numeric-value current-prefix-arg))))
  (setq url (eww--dwim-expand-url url))
  (pop-to-buffer-same-window
   (cond
    ((eq arg 4)
     (generate-new-buffer "*eww*"))
    ((eq major-mode 'eww-mode)
     (current-buffer))
    (t
     (get-buffer-create "*eww*"))))
  (eww-setup-buffer)
  ;; Check whether the domain only uses "Highly Restricted" Unicode
  ;; IDNA characters.  If not, transform to punycode to indicate that
  ;; there may be funny business going on.
  (let ((parsed (url-generic-parse-url url)))
    (when (url-host parsed)
      (unless (puny-highly-restrictive-domain-p (url-host parsed))
        (setf (url-host parsed) (puny-encode-domain (url-host parsed)))))
    ;; When the URL is on the form "http://a/../../../g", chop off all
    ;; the leading "/.."s.
    (when (url-filename parsed)
      (while (string-match "\\`/[.][.]/" (url-filename parsed))
        (setf (url-filename parsed) (substring (url-filename parsed) 3))))
    (setq url (url-recreate-url parsed)))
  (plist-put eww-data :url url)
  (plist-put eww-data :title "")
  (eww-update-header-line-format)
  (let ((inhibit-read-only t))
    (insert (format "Loading %s..." url))
    (goto-char (point-min)))
  (let ((url-mime-accept-string eww-accept-content-types))
    (if buffer
        (let ((eww-buffer (current-buffer)))
          (with-current-buffer buffer
            (eww-render nil url nil eww-buffer)))
      (eww-retrieve url #'eww-render
                    (list url nil (current-buffer))))))



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-12 14:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-11  9:28 To fetch URL, extract <title> element? Jean Louis
2020-11-11 15:27 ` Michael Heerdegen
2020-11-11 18:04   ` Jean Louis
2020-11-12 12:56     ` Michael Heerdegen
2020-11-12 13:20       ` Jean Louis
2020-11-12 14:49     ` Yuri Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).