Can applescript POST data to the active IE Window?

Well, the topic says it all… can anyone tell me how to post data to a form in an active IE 5 window? Please bear in mind that I know absolutely nothing about appelscript, I’m a Java developer who was tasked with making this happen in AS. I’ve gotten AS to open IE to the correct page easy enough, but I am completely lost at this point, I dont know how to reference the form data in the open window, I dont know how to set the text in the text fields , and I dont know how to trigger a search button based off that form when its done. To further muddy the waters, the apple I’m working on is a G3 imac running OS9, and I’ve never had to code on a mac before. I haven’t been able to find a damn thing online about scripting IE with applescript. So, if anyone can help here, I would really really apreciate it. Example code would be great, as would any reference docs or sites out there that you pro Applescripters use when you need to look up something.

Thanks for any help you can give me,
Rich

i had the same problem, but have solved it to some degree.

There are a number of avenuesa that you could follow, you could either encode the URL with the search string, you could use javascript to input fields and then click the button, or you could use JS and extra suites to move and click the mouse.

The best would be the URL encode, well for my solution i was.

Basically you will need to have alook at the form source code and find the relevant form field values. You will also have to find the url address that the form submits to.

Then you would do something like this:


tell app "Internet explorer"
openURL "[url=http://www.thesearchsite.com/search.asp?value=2ksosjd]http://www.thesearchsite.com/search.asp?value="2ksosjd[/url]"
end tell

This would open the search.asp site with a search value of 2ksosjd. It wll then search using this value.

Of course this example is completekly fictitious and wont work. But that should give you a start.

There are lots of posts started by me with the same problems that you will face.

Does that help a little??

your best bet is to search the bbs|forum and look under POST form, or something similar.

In my honest opinion it shouldnt be to hard.

also all that works in osx, sorry.

But give it ago.

JJ was quite helpful too. oh and the IE help is crap

I’ll give it a shot when I get into the office this morning. Thanks for your help :slight_smile: Out of curiosity, does anyone have a website or online documentation detailing how to control IE with applescript? You guys are right when you say that the documentation provided is worthless… :frowning:

Rich

Ok, I got the form fields to populate, but now I would like to trigger a piece of java script running in the page. On the page I just entered data into, there is a javascript function called “searchOperation()”. I would love to be able to trigger that op from my applescript as well. Is this possible?

Thanks again!
Rich

The explorer applescript dictionary has a term for submitting form data in the POST method. Most examples here use the GET method and will not work with POST. Use “FormData” to submit directly without using java.

Format of formdata is"
OpenURL “http://whatever/whatever/” FormData ( “field=” & variable & “&field2=” & “data”)

You get the URL and fields from the source of the page with the form.

i am guessing to run that script you just put this in you IE tell blocks


do script "theScript()"

i think that should work, you might have to link it in i dont know.

I would PM jj as he knows loads about js and AS.

As for the previous post, the way i mentioned to post the URl also works for post.

Hi! And tx to your for your sweet comments :oops:

Not exactly documentation, but a big collection of handlers on IE javAS-cripting, thought for OS 9. Some handlers won’t work in the new OS X (eg, “bookmark”), but most of them still work good:
http://www.macscripter.net/scriptbuilders/category.php?id=580

Oh! I forgot it… Perhaps not interesting for you, but may be for others, a quick tutorial on IE scripting (in spanish!):
http://homepage.mac.com/julifos/assartik/articulos/asapp/asie.html

Usually, javascript functions are attached to the “document” object; so, this should work in most of cases:

do script "document.searchOperation()"

This may be slighly different if we are working with frames. Eg:

do script "top.frames[2].document.searchOperation()"

If you find some problem, you could post here a URL with the related page… :?:

Thanks for the links, I’ve got the MSIE library now, I’ll play with that today. I’ld post the link to the site I’m working in, but its in the back end of a large e-com site, and its password protected to get in. I’ve tried all the sugestions about getting data to post, and making the remote javascript code run, but none of it worked :frowning: The site was very poorly written in JSP, which is outputting javascript, and the data fields dont appear to be in a real web form, so I can’t pass in values by form field name. I’m afraid I’m stuck here. I’m told I can do more things, like send keystrokes to IE with applescript in OSX, but I can’t use OSX for this. I’ll keep working on it, but at this point, it may be easier for me to just try to write something in Java, (which I’ve coded professionally for years) instead of working with a scripting language I didn’t even know existed until 2 weeks ago :wink:

Anyway, thanks for the help so far! Even knowing that what I’m trying to do can’t be done is preferable to not knowing anything, and wasting more time trying to find out :wink:

Rich

Hi Rich_A…

I tried doing a similar sort of job a few years ago, but without much success at the time: I found that the site I was dealing with was using cookies, among other complications, and I came to the conclusion that I had to control a full web browser, perhaps with scripting, to do the job (which then meant I couldn’t schedule the job automatically with cron :().

However, it looks like there are better tools now, and you might be better off with a tool designed to do automation rather than trying to script a full web browser. Try searching Google for “web screen scraping”… you might find some useful resources. http://www.steptwo.com.au/columntwo/archives/000490.html gives a short list: I should think there are more. (Screen scraping is a term that goes way back… expect is an excellent language I’ve used for scraping information out of text-mode interfaces to do useful things.)

There is an article about Perl’s WWW::Mechanize module at http://www.perl.com/pub/a/2003/01/22/mechanize.html which makes some of this look relatively easy: it can be configured to cope with cookies. I don’t know if this will cope with your Javascript complications though.

can you posta link to the source code and we might be able to help you abit more.

Alas i dont know os9 as before 6 weeks ago i have never used apple macs, let alone Apple script, but i have also been trying what you said and to be honest it did seem that it wouldn;t be possible but it works beutifully.

So maybe we can sort out at least alittle to nake your life easier.

I can post here successfully via applescript using “curl” and this site requires cookies… It’s not difficult!.. And there are only two things able to pass data to web apps: forms and links; both under full-control of javascript.

I dont know how the site I’m working with uses cookies, and Im not familar with curl. The site I’m working with is the merchant interface to amazon.com, its basically a tool to let customer merchants (i.e., companies that list products on amazon directly, or use amazon’s web storefront hosting service to run their own ecommerce sites) enter their inventory directly into their database. The real pain with that website, is that the item manager (thats the name of their tool) has dozzens of differnt interfaces, forms, and information pages. However, its all generated by the same piece of JSP code. I have to use 3 different pages on this tool to look up given item, choose the detailed description, then enter data for that item, but since its all the same page, my FormData and encoded URL’s are completely ignored. Nothing I’ve tried has had any effect at all on the open page.

The goal here, by the way, is to save my company the effort of manually entering 50,000 items by hand into this webform. We have all of these items already in our local SQL database, but the amazon site doesn’t have a working method for us to send them a lump of data. If I can get this fully automated, or even partially automated, I can save my data entry department a great deal of time. If I can’t, then they have to do it all by hand, in less than a month :frowning: I was told that if I could get this working in applescript, the company that makes our database software for us can integrate that script into their code, which can pull data directly out of our database. This means we can put a trained monkey in front of the software, and let them push a button to upload our inventory.

Like I said, I’m not a scripter, I’ve never used applescript before this, so I’m quite willing to believe it can’t do what I need it too. I still have hope for my data entry people, apparently there is a PERL script that amazon wrote to upload flat files right into their database. If I can get ahold of someone there who knows what it is and how to use it, I can get all the data uploaded in one batch, which would be perfect. However, until thats a definite, I have to keep working with the applescript plan. Here is a run down of the steps, with what I know about each step so far:

  1. log into the site: I can log in once, manually, and the browser rememers my login (evidence of cookies here) for the rest of the day.
  2. click on the item manager link
  3. on this page, there is a search form. There is a field in there, labeld searchAsin (the page source has it listed as that field name). I need to drop a value in this field.
  4. press the search button
  5. click on the editorial link (this is what they call their detailed description page, its the page that lets me enter all the extra data I need to enter)
  6. crawl down the detailed form, entering data and checking checkboxes as I go for the given product. I have the source as output by the JSP for this page as well, so I can get field names if I can figure out how to put data in them.
  7. click the save button
  8. click on the item manager link, to go back to the search page
  9. repeat steps 3 - 8 50,000 times.

I’m afraid this is too complicated a task for applescript to deal with, but I’m still very open to suggestions, and I’m very glad for the help you all have already given me :slight_smile:

Thanks again,
Rich

AppleScript can help you to get data and as a simple interface to go here-and-there, but, definitivelly, you need a quick “curl” tutorial, which can handle cookies, users, passwords, POST, GET and absolutelly all related stuff… With curl’s help, I did here some time ago aproximatelly 8000+ successfull queries to this forum in less than 24 hours (see “man curl” in the Terminal). I don’t know if it can retrieve cookies, but it can send them as login data for sure.

IE’s javascripting can also do it, but we should see the related pages to help you more accuratelly… Maybe, as long as you won’t provide your user/pwd stuff, you can post here the source-code of such pages (and substitute with asterisks, if needed, some valuable keywords for you), or a page where you find problems.

Amazon.com has a developers area that you can get the Amazon API. There are examples provided that show how to use the Services with many differant languages for the web. Java, PHP, VBA, XLT and SOAP are the main ways of using the Amazon API. One could spend the time learning PERL or cURL to do the job too. Though I think what you really need to do is get that API and work with it, since much of the work might very well be done for you.
The download for the SDK is here:
http://www.amazon.com/gp/browse.html/?node=3434641
Get your Developers Token which is the key to using AWS’s API:
https://associates.amazon.com/exec/panama/associates/join/developer/application.html

One can script Applescript to make and receive the SOAP information:
http://www.apple.com/applescript/webservices/
http://developer.apple.com/documentation/AppleScript/Conceptual/soapXMLRPC/chapter2/chapter_2_section_3.html

An example of Applescript and SOAP in a real world setting by Rael Dornfest (rael@oreilly.com). Though this is now broke because google changed thier webAPI

on google_Search(in_maxResults, in_start, in_filter, in_q,
in_restrict, in_safeSearch)
 
 set in_lr to "" -- language restrict
 set in_ie to "utf8" -- input encoding
 set in_oe to "utf8" -- output encoding
 set in_key to "insert key here" -- my google key 
 
 tell application "http://api.google.com/search/beta2"
  set mn to "doGoogleSearch"
  set sa to "urn:GoogleSearchAction"
  set mns to "urn:GoogleSearch"
  set params to {}
  set params to {oe:in_oe} & params
  set params to {ie:in_ie} & params
  set params to {lr:in_lr} & params
  set params to {|safeSearch|:in_safeSearch} & params
  set params to {restrict:in_restrict} & params
  set params to {filter:in_filter} & params
  set params to {|maxResults|:in_maxResults} & params
  set params to {start:in_start} & params
  set params to {q:in_q} & params
  set params to {|key|:in_key} & params
  return call soap {method name:mn, parameters:params, SOAPAction:sa,
method namespace uri:mns}
 end tell
end google_Search

google_Search(10, 0, false, "applescript", "", false)

One other place that be of use to look into this is google.public.web-apis

Good Luck and post what you learn.

Edited:

Also, at this site in scriptbuilders, Tim Jarrett has provided some great stuff for SOAP with applescript. Check out his site too:
[url]http://jarretthousenorth.editthispage.com/scripts[/url