"Invisibly" Handle HTML Forms?

Is there any way to use HTML forms (such as text fields, buttons, etc.) “invisibly”? ie the user sees nothing.

For example, cURL can give you the source “invisibly”, but I’ve looked around the documentation and found no way to use forms.

I could just open it in Safari then quickly close it, but I really do not want the user to see anything happening.

What I want to use this for is a website that my school uses to tell us our grades, but we need to log in first. I want to automate the whole process, and simply run an app, enter the username/password, parse some HTML, and display my grades in a handy dialog.

Of course, I can do all the parsing myself, but I’m a bit confused about interacting with HTML forms.



I believe there is a way to do that, from the “do Javascript” command. I has some form method. I will look for it for you.

Here is a form that might contain things you’re looking for.

I don’t know if it’s of any use to you, but cURL has an option which returns a more helpful manual. It’s a bit beyond my understanding in the limited time I have this morning, but this script gets you to a tutorial on posting forms:

set curlManualPath to (path to desktop as Unicode text) & "curl Manual.txt"

set fref to (open for access file curlManualPath with write permission)
	set eof fref to 0
	write (do shell script "curl -M") as text to fref
end try
close access fref

tell application "TextEdit" to open file curlManualPath

tell application "System Events"
	tell application process "TextEdit"
		set frontmost to true
		tell window 1
			repeat until (it exists) and (its name is "curl Manual.txt")
				delay 0.2
			end repeat
		end tell
		keystroke "f" using {command down}
		repeat until name of window 1 is "Find"
			delay 0.2
		end repeat
		keystroke "How to post a form with curl"
		keystroke return
	end tell
end tell

@Dylan - I know about that, and use it a lot, but I don’t want Safari to do any of it. I want to do it all through the command line.

@Nigel - Hm, for some reason, that script didn’t work for me, but I got the manual through Terminal. I’ve been looking through it and still haven’t gotten anything to work. But thanks for showing that to me!

It seems cURL is used a lot by PHP coders. So if anyone knows anything about that, could they please help? :wink:


PS the webpage looks like this:

<input name="sid" type="text" maxlength="50" id="sid" onfocus="this.select()" style="width:150px;" />
<input name="pin" type="password" maxlength="20" id="pin" onfocus="this.select()" style="width:150px;" />
<input type="submit" name="btnLogin" value="Login" id="btnLogin" />

PPS here’s what I have, but it isn’t working:

curl -d "sid=username&pin=pass&btnLogin=submit" http://www.xxx.com/

Perhaps the “btnLogin” value should be “Login” rather than “submit”?

What does the element look like?

Actually, on closer inspection, the login text fields aren’t in a form, but in a table… :o (Poor HTML design FTW?)

But there is a form, which looks like this:

<form name="Form1" method="post" action="Login.aspx" id="Form1" autocomplete="off">
<input type="hidden" name="__postbackAction" id="__postbackAction" value="" />

Note that I have no clue what the “__VIEWSTATE”'s value has to do with anything. It’s just random characters.