url-get-url-at-point function from the
url-util (emacs built-in) package should do the job for you. It is used in interactive commands like
(defun my/kill-url-at-point ()
"Kill the url at point."
If you need to copy URL from an HTML page while in an emacs browser like
eww, you can use the
shr-copy-url command directly. The fun thing is that if you consecutively call that command twice while the point is on a hyperlink, it removes the link re-directions too!
C-h f shr-copy-url:
shr-copy-url is an interactive compiled Lisp function in `shr.el'.
(shr-copy-url &optional IMAGE-URL)
For more information check the manuals.
Copy the URL under point to the kill ring.
If IMAGE-URL (the prefix) is non-nil, or there is no link under
point, but there is an image under point then copy the URL of the
image under point instead.
If called twice, then try to fetch the URL and see whether it
redirects somewhere else.
Here's an example of how I use
shr-copy-url in one of my eww snippets.