Re: Entering data in a web page
Re: Entering data in a web page
- Subject: Re: Entering data in a web page
- From: BJ Terry <email@hidden>
- Date: Mon, 17 May 2004 10:38:26 -0700
On May 16, 2004, at 10:33 PM, Brian Cox wrote:
Michael was able to answer my question concerning the password.
However, now
I am trying to enter text into an input field of a web page.
I open a web page using the script.
The web page has several input fields.
I need to select a specific field and enter data.
One option you could consider would be internet explorer's "OpenURL"
command. If the form is a post form, you can open the url with the form
data. Here's an example from everything2.com:
tell application "Internet Explorer"
OpenURL "
http://www.everything2.com/index.pl" toWindow -1 FormData
"node=test;" MIME Type "application/x-www-form-urlencoded"
end tell
Unfortunately, Internet Explorer's implementation of this command seems
broken in some ways. First of all, I believe that the semicolon after
test shouldn't be required, though I may be wrong on that point.
Second, when I tried my more complex script (originally written for
OmniWeb's better implementation of IE's command), it failed for no
reason. It breaks when I add more parameters. I'm not quite sure where
this is occurring, but it may be a subtle bug in IE's implementation. I
will attach that script at the end of this message, to exemplify how
one might construct the FormData string. First I will talk about how to
get information out of the source to make your post request useful.
This is the form source from www.everything2.com:
<form method="post" action="/index.pl"
enctype="application/x-www-form-urlencoded">
<td><input type="text" name="node" size="28" maxlength="80" /><input
type="hidden" name="lastnode_id" value="124"></td><td><input
type="image" name="searchy" border="0" alt="search" align="middle"
src="
http://images.everything2.com/img/search_button.gif"></td><td
style="font-family:sans-serif;">
<input type="checkbox" name="soundex" value="1" default="0"
/><small><small>Near Matches</small></small><br />
<input type="checkbox" name="match_all" value="1" default="0"
/><small><small>Ignore Exact</small></small></td></tr></table>
For IE's command to work, the "method=" of the form must be "post" and
not "get", since get form parameters are encoded directly into the URL.
My Linksys router was post, if I remember correctly, but I don't have
it handy. The second thing is the "enctype=", which you put inside the
"MIME Type" parameter to OpenURL. The third thing is the "action="
which is the relative or absolute URL that you should put in the main
parameter of OpenURL. In this case it's relative, so I appended it to
the main site address. The fourth thing to notice is the input fields.
The name of the input fields is the word "node" in the above script,
and the word "test" is the information I'm sending in that field. You
combine multiple input fields in the same string be separating with
semicolons. So, for everything2.com, your FormData might be
"node=test;soundex=0;match_all=1".
I don't really know too much about posting form data scriptmatically,
as this is about as deep as my knowledge gets me, but hopefully you'll
be able to figure out how it should be set up with your particular
setup. Here's the whole script, which works in OmniWeb but not IE, even
though OW's command is a copy of IE's (I actually made it while I was
testing OmniWeb's scripting implementation for completeness. To their
credit, this command worked without issue in the earliest beta. The
only issue is that it is impossible to post file data, which makes it
unusable for certain types of websites, but I'm not sure how to
approach that, since it's sort of a different thing.):
tell application "Internet Explorer"
set x to item 1 of (ListWindows)
set y to display dialog "What do you want to search for on
Everything2.com?" default answer "test"
set z to display dialog "Near Matches?" buttons {"Yes", "No"} default
button "No"
set a to display dialog "Ignore Exact?" buttons {"Yes", "No"} default
button "No"
set y to y's text returned
if z's button returned is equal to "Yes" then
set z to 1
else
set z to 0
end if
if a's button returned is equal to "Yes" then
set a to 1
else
set a to 0
end if
OpenURL "
http://www.everything2.com/index.pl" toWindow -1 FormData
"node=" & y & ";soundex=" & z & ";match_all=" & a MIME Type
"application/x-www-form-urlencoded" --opens it in the browser window
--format of FormData is "parametername1=value;parametername2=value"
end tell
BJ
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.