[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: Fill in a form (and send it) from Elisp



In [emacs-w3m : No.12212] Emanuel Berg wrote:
> How do you do that?

> My attempts so far:

> (fset 'login-name "embe8573")

> (defun web-login ()
>   (interactive)
>   (w3m-next-anchor 6) ; this works
>   (w3m-view-this-url) ; and this
>   (execute-kbd-macro (symbold-function 'login-name)) )

> But the last line doesn't work, so perhaps the whole
> "macro idea" is a dead end.

> If I know the configuration of a form beforehand, how
> can I write Elisp to fill all fields with data, and
> then likewise pragmatically push the "send" (or so)
> button?

Interesting.  I did it as follows.  If you try it, you may want
to modify the anchor numbers (`m' and `n').  If you don't want
to enter either a login name or a password, remove the section
(`Goto the x-th anchor' ~ `Enter foo').

(fset 'login-name "yamaoka")
(fset 'login-pass "blabla")

(defun web-login ()
  (interactive)
  (let ((m 3) ;; Anchor for login name
	(n 4) ;; Anchor for password
	(name (symbol-function 'login-name))
	(pass (symbol-function 'login-pass))
	(anchor (point-min))
	action)
    ;; Goto the m-th anchor
    (while (and (setq anchor (text-property-not-all anchor (point-max)
						    'w3m-anchor-sequence nil))
		(> (setq m (1- m)) 0)
		(setq anchor (text-property-any anchor (point-max)
						'w3m-anchor-sequence nil))))
    (goto-char anchor)
    ;; Enter login name
    (setq action (w3m-action))
    (w3m-form-put (nth 1 action) (nth 2 action) (nth 3 action) name)
    (w3m-form-replace name)
    ;; Goto the n-th anchor
    (setq anchor (point-min))
    (while (and (setq anchor (text-property-not-all anchor (point-max)
						    'w3m-anchor-sequence nil))
		(> (setq n (1- n)) 0)
		(setq anchor (text-property-any anchor (point-max)
						'w3m-anchor-sequence nil))))
    (goto-char anchor)
    ;; Enter password
    (setq action (w3m-action))
    (w3m-form-put (nth 1 action) (nth 2 action) (nth 3 action) pass)
    (w3m-form-replace pass 'invisible)
    ;; Submit it
    (eval (w3m-submit))))